Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.apt.core/pom.xml2
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java10
-rw-r--r--org.eclipse.jdt.apt.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.apt.tests/pom.xml2
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/build.properties2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin259552 -> 267940 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar (renamed from org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar)bin109915 -> 111292 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/pom.xml2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor1
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java11ElementProcessor.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java13ElementProcessor.java251
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java13ElementsTests.java98
-rw-r--r--org.eclipse.jdt.compiler.apt/build.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt/lib/java13api.jar (renamed from org.eclipse.jdt.compiler.apt/lib/java10api.jar)bin109915 -> 111292 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java33
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/build.properties6
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar (renamed from org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar)bin109915 -> 111292 bytes
-rw-r--r--org.eclipse.jdt.compiler.tool.tests/pom.xml2
-rw-r--r--org.eclipse.jdt.compiler.tool/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.jdt.compiler.tool/build.properties6
-rw-r--r--org.eclipse.jdt.compiler.tool/lib/java13api.jar (renamed from org.eclipse.jdt.compiler.tool/lib/java10api.jar)bin109915 -> 111292 bytes
-rw-r--r--org.eclipse.jdt.compiler.tool/pom.xml2
-rw-r--r--org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.core.tests.builder/pom.xml2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/pom.xml30
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java14
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java1
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest.java34
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java293
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest13.java1070
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java22
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java46
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java48
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java704
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java1
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java255
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java14
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java68
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java1231
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java3483
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java20
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java65
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java45
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java6
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java43
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/jclMin13.jarbin0 -> 21029 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zipbin0 -> 9434 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/pom.xml31
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java9
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java96
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java11
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java82
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter11Test.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java (renamed from org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java)308
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java92
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java28
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java18
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java44
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs12Tests.java626
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java1047
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java10
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java18
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java30
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java20
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter13/.classpath (renamed from org.eclipse.jdt.core.tests.model/workspace/Converter12/.classpath)0
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter13/.project (renamed from org.eclipse.jdt.core.tests.model/workspace/Converter12/.project)0
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter13/src/X.java (renamed from org.eclipse.jdt.core.tests.model/workspace/Converter12/src/X.java)0
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/A_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/B_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/in.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java8
-rw-r--r--org.eclipse.jdt.core.tests.performance/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.core.tests.performance/pom.xml2
-rw-r--r--org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java4
-rw-r--r--org.eclipse.jdt.core/.settings/.api_filters84
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java14
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java64
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java9
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java113
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java17
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java81
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java58
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TextBlock.java20
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/YieldStatement.java182
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/messages.properties2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ConflictedParser.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java1224
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ParserBasicInformation.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java356
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java21
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/TerminalTokens.java173
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser1.rscbin34470 -> 34178 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser10.rscbin596 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser11.rscbin596 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser12.rscbin596 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser13.rscbin596 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser14.rscbin2362 -> 2360 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser15.rscbin1490 -> 1540 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser16.rscbin2338 -> 2338 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser17.rscbin870 -> 872 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser18.rscbin15614 -> 15994 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser19.rscbin596 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser2.rscbin32730 -> 32434 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser20.rscbin16888 -> 16952 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser21.rscbin6960 -> 6976 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser22.rscbin796 -> 798 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser23.rscbin90 -> 90 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser24.rscbin796 -> 798 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser3.rscbin2338 -> 2338 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser4.rscbin3468 -> 3500 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser5.rscbin2338 -> 2338 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser6.rscbin1416 -> 1418 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser7.rscbin262 -> 264 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser8.rscbin796 -> 798 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser9.rscbin15488 -> 15904 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/readableNames.props1
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/part0.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/part1.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/part14.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/part2.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/start0.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/start1.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode12_1/start2.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java114
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties25
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Messages.java1
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java233
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java64
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java56
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java60
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java1
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java70
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java76
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java18
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java1
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java36
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java17
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TextBlock.java296
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/YieldStatement.java247
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java2
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java42
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java38
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java44
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java6
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java9
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java15
-rw-r--r--org.eclipse.jdt.core/grammar/java.g20
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java8
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java4
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/PublicScanner.java1
-rw-r--r--org.eclipse.jdt.tests.latestBREE/.classpath15
-rw-r--r--org.eclipse.jdt.tests.latestBREE/.project28
-rw-r--r--org.eclipse.jdt.tests.latestBREE/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--org.eclipse.jdt.tests.latestBREE/.settings/org.eclipse.jdt.core.prefs115
-rw-r--r--org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF22
-rw-r--r--org.eclipse.jdt.tests.latestBREE/build.properties4
-rw-r--r--org.eclipse.jdt.tests.latestBREE/pom.xml78
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TestAll.java34
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/compiler/regression/latest/TextBlockTest.java879
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/core/tests/model/CompletionTests13.java (renamed from org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java)849
-rw-r--r--org.eclipse.jdt.tests.latestBREE/src/org/eclipse/jdt/tests/latestbree/Activator.java22
-rw-r--r--org.eclipse.jdt.tests.latestBREE/test.xml68
-rw-r--r--pom.xml2
212 files changed, 13557 insertions, 3256 deletions
diff --git a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
index f1ea17f592..9ca7812987 100644
--- a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.core; singleton:=true
-Bundle-Version: 3.6.500.qualifier
+Bundle-Version: 3.6.550.qualifier
Bundle-Localization: plugin
Export-Package: com.sun.mirror.apt,
com.sun.mirror.declaration,
diff --git a/org.eclipse.jdt.apt.core/pom.xml b/org.eclipse.jdt.apt.core/pom.xml
index 618043fbdd..d6b10df7cc 100644
--- a/org.eclipse.jdt.apt.core/pom.xml
+++ b/org.eclipse.jdt.apt.core/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.apt.core</artifactId>
- <version>3.6.500-SNAPSHOT</version>
+ <version>3.6.550-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
index a772cef6fe..c893542686 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
@@ -86,7 +86,7 @@ import com.sun.mirror.util.Types;
public class BaseProcessorEnv implements AnnotationProcessorEnvironment
{
static{
- final AST ast = AST.newAST(AST.JLS11, false);
+ final AST ast = AST.newAST(AST.JLS13, true);
EMPTY_AST_UNIT = ast.newCompilationUnit();
}
public static final CompilationUnit EMPTY_AST_UNIT;
@@ -508,7 +508,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
}
final BindingRequestor requestor = new BindingRequestor();
- final ASTParser parser = ASTParser.newParser(AST.JLS11);
+ final ASTParser parser = ASTParser.newParser(AST.JLS13);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setProject(_javaProject);
@@ -719,7 +719,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
if( astUnit != null ) return astUnit;
else{
// Note: very expensive operation. we are re-compiling a file with binding information.
- final ASTParser parser = ASTParser.newParser(AST.JLS11);
+ final ASTParser parser = ASTParser.newParser(AST.JLS13);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setSource(unit);
@@ -868,7 +868,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
String bogusKey = BindingKey.createTypeBindingKey("java.lang.Object"); //$NON-NLS-1$
String[] keys = new String[] {bogusKey};
- ASTParser p = ASTParser.newParser( AST.JLS11 );
+ ASTParser p = ASTParser.newParser( AST.JLS13 );
p.setResolveBindings(true);
p.setBindingsRecovery(true);
p.setProject( javaProject );
@@ -898,7 +898,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
}
CompilationUnitRequestor requestor = new CompilationUnitRequestor();
- ASTParser p = ASTParser.newParser( AST.JLS11 );
+ ASTParser p = ASTParser.newParser( AST.JLS13 );
p.setResolveBindings(true);
p.setBindingsRecovery(true);
p.setProject( javaProject );
diff --git a/org.eclipse.jdt.apt.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.tests/META-INF/MANIFEST.MF
index b36858f0bd..056e70f0e9 100644
--- a/org.eclipse.jdt.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.tests; singleton:=true
-Bundle-Version: 3.4.500.qualifier
+Bundle-Version: 3.4.550.qualifier
Bundle-ClassPath: apt.jar,
aptext.jar,
.
diff --git a/org.eclipse.jdt.apt.tests/pom.xml b/org.eclipse.jdt.apt.tests/pom.xml
index 487982f994..9ec0feeed9 100644
--- a/org.eclipse.jdt.apt.tests/pom.xml
+++ b/org.eclipse.jdt.apt.tests/pom.xml
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.apt.tests</artifactId>
- <version>3.4.500-SNAPSHOT</version>
+ <version>3.4.550-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java
index 338f6a637a..4bb75181c6 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 BEA Systems, Inc.
+ * Copyright (c) 2005, 2019 BEA Systems, Inc.
*
* 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:
* tyeung@bea.com - initial API and implementation
*******************************************************************************/
@@ -187,7 +187,7 @@ public class ReadAnnotationTests2 extends BuilderTests {
}
final BindingRequestor requestor = new BindingRequestor();
- final ASTParser parser = ASTParser.newParser(AST.JLS11);
+ final ASTParser parser = ASTParser.newParser(AST.JLS13);
parser.setResolveBindings(true);
parser.setProject(javaProj);
parser.setIgnoreMethodBodies(true);
diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath
index 8102373411..6d7726d275 100644
--- a/org.eclipse.jdt.compiler.apt.tests/.classpath
+++ b/org.eclipse.jdt.compiler.apt.tests/.classpath
@@ -16,7 +16,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java10api.jar"/>
+ <classpathentry kind="lib" path="lib/java13api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
index 1a73c03f52..6c7e345b25 100644
--- a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.compiler.apt.tests;singleton:=true
-Bundle-Version: 1.1.900.qualifier
+Bundle-Version: 1.1.850.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -19,6 +19,6 @@ Export-Package: org.eclipse.jdt.compiler.apt.tests,
org.eclipse.jdt.compiler.apt.tests.processors.visitors
Import-Package: org.eclipse.jdt.internal.compiler.tool;resolution:=optional
Eclipse-BundleShape: dir
-Bundle-ClassPath: lib/java10api.jar,
+Bundle-ClassPath: lib/java13api.jar,
.
Automatic-Module-Name: org.eclipse.jdt.compiler.apt.tests
diff --git a/org.eclipse.jdt.compiler.apt.tests/build.properties b/org.eclipse.jdt.compiler.apt.tests/build.properties
index e9a85ccd3b..cddfe5d640 100644
--- a/org.eclipse.jdt.compiler.apt.tests/build.properties
+++ b/org.eclipse.jdt.compiler.apt.tests/build.properties
@@ -27,4 +27,4 @@ bin.includes = about.html,\
.
src.includes = about.html
compilerArg=-proc:none
-jars.extra.classpath = lib/java10api.jar
+jars.extra.classpath = lib/java13api.jar
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index e51a6bcf7f..c0e46191a6 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar
index 464b69134f..d8bbb8b501 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/java13api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/pom.xml b/org.eclipse.jdt.compiler.apt.tests/pom.xml
index 8406059ff3..06f74dd605 100644
--- a/org.eclipse.jdt.compiler.apt.tests/pom.xml
+++ b/org.eclipse.jdt.compiler.apt.tests/pom.xml
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.compiler.apt.tests</artifactId>
- <version>1.1.900-SNAPSHOT</version>
+ <version>1.1.850-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
index 22707a258c..f706af86b9 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
@@ -2,3 +2,4 @@ org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor
org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java13ElementProcessor
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java11ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java11ElementProcessor.java
index 590205e9d7..71cae2d8e7 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java11ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java11ElementProcessor.java
@@ -33,7 +33,7 @@ import javax.tools.JavaFileObject;
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
/**
- * A processor that explores the java 9 specific elements and validates the lambda and
+ * A processor that explores the java 11 specific elements and validates the lambda and
* type annotated elements. To enable this processor, add
* -Aorg.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor to the command line.
* @since 3.14
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
index f8699c6b7c..51c634a4f8 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
@@ -40,7 +40,7 @@ import javax.lang.model.element.TypeElement;
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
/**
- * A processor that explores the java 9 specific elements and validates the lambda and
+ * A processor that explores the java 12 specific elements and validates the lambda and
* type annotated elements. To enable this processor, add
* -Aorg.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor to the command line.
* @since 3.14
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java13ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java13ElementProcessor.java
new file mode 100644
index 0000000000..5dcb8be92a
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java13ElementProcessor.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation.
+ *
+ * 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.compiler.apt.tests.processors.elements;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
+import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
+
+/**
+ * A processor that explores the java 13 specific elements and validates the lambda and
+ * type annotated elements. To enable this processor, add
+ * -Aorg.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor to the command line.
+ * @since 3.14
+ */
+@SupportedAnnotationTypes("*")
+public class Java13ElementProcessor extends BaseProcessor {
+ boolean reportSuccessAlready = true;
+ RoundEnvironment roundEnv = null;
+ Messager _messager = null;
+ Filer _filer = null;
+ boolean isBinaryMode = false;
+ String mode;
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ _elementUtils = processingEnv.getElementUtils();
+ _messager = processingEnv.getMessager();
+ _filer = processingEnv.getFiler();
+ }
+ // Always return false from this processor, because it supports "*".
+ // The return value does not signify success or failure!
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver()) {
+ return false;
+ }
+
+ this.roundEnv = roundEnv;
+ Map<String, String> options = processingEnv.getOptions();
+ if (!options.containsKey(this.getClass().getName())) {
+ // Disable this processor unless we are intentionally performing the test.
+ return false;
+ } else {
+ try {
+ if (options.containsKey("binary")) {
+ this.isBinaryMode = true;
+ this.mode = "binary";
+ } else {
+ this.mode = "source";
+ }
+ if (!invokeTestMethods(options)) {
+ testAll();
+ }
+ if (this.reportSuccessAlready) {
+ super.reportSuccess();
+ }
+ } catch (AssertionFailedError e) {
+ super.reportError(getExceptionStackTrace(e));
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ private boolean invokeTestMethods(Map<String, String> options) throws Throwable {
+ Method testMethod = null;
+ Set<String> keys = options.keySet();
+ boolean testsFound = false;
+ for (String option : keys) {
+ if (option.startsWith("test")) {
+ try {
+ testMethod = this.getClass().getDeclaredMethod(option, new Class[0]);
+ if (testMethod != null) {
+ testsFound = true;
+ testMethod.invoke(this, new Object[0]);
+ }
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ } catch (Exception e) {
+ super.reportError(getExceptionStackTrace(e));
+ }
+ }
+ }
+ return testsFound;
+ }
+
+ public void testAll() throws AssertionFailedError, IOException {
+ testPreviewFlagTrue();
+ testPreviewFlagFalse();
+ }
+
+ public void testPreviewFlagTrue() throws IOException {
+ if (this.processingEnv instanceof BaseProcessingEnvImpl) {
+ boolean preview = ((BaseProcessingEnvImpl) this.processingEnv).isPreviewEnabled();
+ assertTrue("Preview flag not seen as enabled", preview);
+ }
+ }
+ public void testPreviewFlagFalse() throws IOException {
+ if (this.processingEnv instanceof BaseProcessingEnvImpl) {
+ boolean preview = ((BaseProcessingEnvImpl) this.processingEnv).isPreviewEnabled();
+ assertFalse("Preview flag not seen as enabled", preview);
+ }
+ }
+
+ @Override
+ public void reportError(String msg) {
+ throw new AssertionFailedError(msg);
+ }
+ private String getExceptionStackTrace(Throwable t) {
+ StringBuffer buf = new StringBuffer(t.getMessage());
+ StackTraceElement[] traces = t.getStackTrace();
+ for (int i = 0; i < traces.length; i++) {
+ StackTraceElement trace = traces[i];
+ buf.append("\n\tat " + trace);
+ if (i == 12)
+ break; // Don't dump all stacks
+ }
+ return buf.toString();
+ }
+ protected String getElementsAsString(List<? extends Element> list) {
+ StringBuilder builder = new StringBuilder("[");
+ for (Element element : list) {
+ if (element instanceof PackageElement) {
+ builder.append(((PackageElement) element).getQualifiedName());
+ } else if (element instanceof ModuleElement) {
+ builder.append(((ModuleElement) element).getQualifiedName());
+ } else if (element instanceof TypeElement) {
+ builder.append(((TypeElement) element).getQualifiedName());
+ } else {
+ builder.append(element.getSimpleName());
+ }
+ builder.append(", ");
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+ public void assertModifiers(Set<Modifier> modifiers, String[] expected) {
+ assertEquals("Incorrect no of modifiers", modifiers.size(), expected.length);
+ Set<String> actual = new HashSet<String>(expected.length);
+ for (Modifier modifier : modifiers) {
+ actual.add(modifier.toString());
+ }
+ for(int i = 0, length = expected.length; i < length; i++) {
+ boolean result = actual.remove(expected[i]);
+ if (!result) reportError("Modifier not present :" + expected[i]);
+ }
+ if (!actual.isEmpty()) {
+ reportError("Unexpected modifiers present:" + actual.toString());
+ }
+ }
+ public void assertTrue(String msg, boolean value) {
+ if (!value) reportError(msg);
+ }
+ public void assertFalse(String msg, boolean value) {
+ if (value) reportError(msg);
+ }
+ public void assertSame(String msg, Object obj1, Object obj2) {
+ if (obj1 != obj2) {
+ reportError(msg + ", should be " + obj1.toString() + " but " + obj2.toString());
+ }
+ }
+ public void assertNotSame(String msg, Object obj1, Object obj2) {
+ if (obj1 == obj2) {
+ reportError(msg + ", " + obj1.toString() + " should not be same as " + obj2.toString());
+ }
+ }
+ public void assertNotNull(String msg, Object obj) {
+ if (obj == null) {
+ reportError(msg);
+ }
+ }
+ public void assertNull(String msg, Object obj) {
+ if (obj != null) {
+ reportError(msg);
+ }
+ }
+ public void assertEquals(String message, Object expected, Object actual) {
+ if (equalsRegardingNull(expected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ public void assertEquals(String message, Object expected, Object alternateExpected, Object actual) {
+ if (equalsRegardingNull(expected, actual) || equalsRegardingNull(alternateExpected, actual)) {
+ return;
+ } else {
+ reportError(message + ", expected " + expected.toString() + " but was " + actual.toString());
+ }
+ }
+
+ static boolean equalsRegardingNull(Object expected, Object actual) {
+ if (expected == null) {
+ return actual == null;
+ }
+ return expected.equals(actual);
+ }
+
+ public void assertEquals(String msg, int expected, int actual) {
+ if (expected != actual) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(msg);
+ buf.append(", expected " + expected + " but was " + actual);
+ reportError(buf.toString());
+ }
+ }
+ public void assertEquals(Object expected, Object actual) {
+ if (expected != actual) {
+
+ }
+ }
+ private class AssertionFailedError extends Error {
+ private static final long serialVersionUID = 1L;
+
+ public AssertionFailedError(String msg) {
+ super(msg);
+ }
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java13ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java13ElementsTests.java
new file mode 100644
index 0000000000..78aa8b7204
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java13ElementsTests.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation.
+ *
+ * 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.compiler.apt.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.SourceVersion;
+import javax.tools.JavaCompiler;
+
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
+import junit.framework.TestCase;
+
+public class Java13ElementsTests extends TestCase {
+ private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java13ElementProcessor";
+
+ public void testPreviewFlagTrue() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "13", "testPreviewFlagTrue", null, "modules2", true);
+ }
+ public void testPreviewFlagFalse() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithPreview(compiler, MODULE_PROC, "13", "testPreviewFlagFalse", null, "modules2", false);
+ }
+
+ protected void internalTestWithPreview(JavaCompiler compiler, String processor, String compliance,
+ String testMethod, String testClass, String resourceArea, boolean preview) throws IOException {
+ if (!canRunJava13()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "mod_locations", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("mod_locations/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("mod_locations/" + resourceArea + "/" + testClass, targetFolder);
+ }
+
+ List<String> options = new ArrayList<String>();
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ options.add("-processor");
+ options.add(processor);
+ // Javac 1.8 doesn't (yet?) support the -1.8 option
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-" + compliance);
+ } else {
+ options.add("-source");
+ options.add(compliance);
+ }
+ if (preview)
+ options.add("--enable-preview");
+ BatchTestUtils.compileInModuleMode(compiler, options, processor, targetFolder, null, true);
+ // If it succeeded, the processor will have set this property to "succeeded";
+ // if not, it will set it to an error value.
+ assertEquals("succeeded", System.getProperty(processor));
+ }
+ public boolean canRunJava13() {
+ try {
+ SourceVersion.valueOf("RELEASE_13");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ BatchTestUtils.init();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt/build.properties b/org.eclipse.jdt.compiler.apt/build.properties
index 7e1102b5c5..6b49b018ed 100644
--- a/org.eclipse.jdt.compiler.apt/build.properties
+++ b/org.eclipse.jdt.compiler.apt/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2017 IBM Corporation and others.
+# Copyright (c) 2005, 2019 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -22,4 +22,4 @@ jars.compile.order = .
output.. = bin/
source.. = src/
-jars.extra.classpath = lib/java10api.jar
+jars.extra.classpath = lib/java13api.jar
diff --git a/org.eclipse.jdt.compiler.apt/lib/java10api.jar b/org.eclipse.jdt.compiler.apt/lib/java13api.jar
index 464b69134f..d8bbb8b501 100644
--- a/org.eclipse.jdt.compiler.apt/lib/java10api.jar
+++ b/org.eclipse.jdt.compiler.apt/lib/java13api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
index f288a44543..5a088fbf6e 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 BEA Systems, Inc.
+ * Copyright (c) 2007, 2019 BEA Systems, Inc.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -129,11 +129,33 @@ public abstract class BaseProcessingEnvImpl implements ProcessingEnvironment {
return SourceVersion.RELEASE_6;
}
try {
- return SourceVersion.valueOf("RELEASE_7"); //$NON-NLS-1$
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_7) {
+ return SourceVersion.valueOf("RELEASE_7"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_8) {
+ return SourceVersion.valueOf("RELEASE_8"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK9) {
+ return SourceVersion.valueOf("RELEASE_9"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK10) {
+ return SourceVersion.valueOf("RELEASE_10"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK11) {
+ return SourceVersion.valueOf("RELEASE_11"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK12) {
+ return SourceVersion.valueOf("RELEASE_12"); //$NON-NLS-1$
+ }
+ if (this._compiler.options.sourceLevel == ClassFileConstants.JDK13) {
+ return SourceVersion.valueOf("RELEASE_13"); //$NON-NLS-1$
+ }
} catch(IllegalArgumentException e) {
// handle call on a JDK 6
return SourceVersion.RELEASE_6;
}
+ // handle call on a JDK 6 by default
+ return SourceVersion.RELEASE_6;
}
/**
@@ -174,5 +196,12 @@ public abstract class BaseProcessingEnvImpl implements ProcessingEnvironment {
_addedClassFiles.toArray(result);
return result;
}
+ /*
+ * This overrides ProcessingEnvironment, but can't declare so since
+ * we are still compiling against JDK 8.
+ */
+ public boolean isPreviewEnabled() {
+ return this._compiler.options.enablePreviewFeatures;
+ }
}
diff --git a/org.eclipse.jdt.compiler.tool.tests/.classpath b/org.eclipse.jdt.compiler.tool.tests/.classpath
index fc20dc52b3..1aaf22970c 100644
--- a/org.eclipse.jdt.compiler.tool.tests/.classpath
+++ b/org.eclipse.jdt.compiler.tool.tests/.classpath
@@ -6,7 +6,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java10api.jar"/>
+ <classpathentry kind="lib" path="lib/java13api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF
index eb56b0df36..54d07eb5eb 100644
--- a/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.compiler.tool.tests
-Bundle-Version: 1.2.500.qualifier
+Bundle-Version: 1.2.550.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/org.eclipse.jdt.compiler.tool.tests/build.properties b/org.eclipse.jdt.compiler.tool.tests/build.properties
index c7599cfabc..e40bb4927f 100644
--- a/org.eclipse.jdt.compiler.tool.tests/build.properties
+++ b/org.eclipse.jdt.compiler.tool.tests/build.properties
@@ -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
@@ -16,9 +16,9 @@ bin.includes = META-INF/,\
about.html,\
plugin.properties,\
test.xml,\
- lib/java10api.jar,\
+ lib/java13api.jar,\
resources/
src.includes = about.html
source.. = src/
output.. = bin/
-jars.extra.classpath = lib/java10api.jar
+jars.extra.classpath = lib/java13api.jar
diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar
index 464b69134f..d8bbb8b501 100644
--- a/org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar
+++ b/org.eclipse.jdt.compiler.tool.tests/lib/java13api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.tool.tests/pom.xml b/org.eclipse.jdt.compiler.tool.tests/pom.xml
index 753355545b..6960622abb 100644
--- a/org.eclipse.jdt.compiler.tool.tests/pom.xml
+++ b/org.eclipse.jdt.compiler.tool.tests/pom.xml
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.compiler.tool.tests</artifactId>
- <version>1.2.500-SNAPSHOT</version>
+ <version>1.2.550-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.jdt.compiler.tool/.classpath b/org.eclipse.jdt.compiler.tool/.classpath
index a3b97caae2..59c1bb0063 100644
--- a/org.eclipse.jdt.compiler.tool/.classpath
+++ b/org.eclipse.jdt.compiler.tool/.classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="lib/java10api.jar"/>
+ <classpathentry kind="lib" path="lib/java13api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
index 0a2c73252c..aff73d2838 100644
--- a/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.tool/META-INF/MANIFEST.MF
@@ -2,13 +2,13 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %fragmentName
Bundle-SymbolicName: org.eclipse.jdt.compiler.tool;singleton:=true
-Bundle-Version: 1.2.600.qualifier
+Bundle-Version: 1.2.550.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: compiler_tool_fragment
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: META-INF.services,
org.eclipse.jdt.internal.compiler.tool;x-internal:=true
Fragment-Host: org.eclipse.jdt.core;bundle-version="[3.3.0,4.0.0)"
-Bundle-ClassPath: lib/java10api.jar,
+Bundle-ClassPath: lib/java13api.jar,
.
Automatic-Module-Name: org.eclipse.jdt.compiler.tool
diff --git a/org.eclipse.jdt.compiler.tool/build.properties b/org.eclipse.jdt.compiler.tool/build.properties
index fd418f7960..42961c2cfe 100644
--- a/org.eclipse.jdt.compiler.tool/build.properties
+++ b/org.eclipse.jdt.compiler.tool/build.properties
@@ -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
@@ -18,6 +18,6 @@ bin.includes = META-INF/,\
.,\
about.html,\
compiler_tool_fragment.properties,\
- lib/java10api.jar
+ lib/java13api.jar
src.includes = about.html
-jars.extra.classpath = lib/java10api.jar \ No newline at end of file
+jars.extra.classpath = lib/java13api.jar \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.tool/lib/java10api.jar b/org.eclipse.jdt.compiler.tool/lib/java13api.jar
index 464b69134f..d8bbb8b501 100644
--- a/org.eclipse.jdt.compiler.tool/lib/java10api.jar
+++ b/org.eclipse.jdt.compiler.tool/lib/java13api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.tool/pom.xml b/org.eclipse.jdt.compiler.tool/pom.xml
index f95ed986f8..ec877471e6 100644
--- a/org.eclipse.jdt.compiler.tool/pom.xml
+++ b/org.eclipse.jdt.compiler.tool/pom.xml
@@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.compiler.tool</artifactId>
- <version>1.2.600-SNAPSHOT</version>
+ <version>1.2.550-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
diff --git a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
index 92bb29bd9b..ccf9aba998 100644
--- a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.builder; singleton:=true
-Bundle-Version: 3.10.700.qualifier
+Bundle-Version: 3.10.750.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.builder
diff --git a/org.eclipse.jdt.core.tests.builder/pom.xml b/org.eclipse.jdt.core.tests.builder/pom.xml
index 4822c31313..e6d81e716a 100644
--- a/org.eclipse.jdt.core.tests.builder/pom.xml
+++ b/org.eclipse.jdt.core.tests.builder/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.builder</artifactId>
- <version>3.10.700-SNAPSHOT</version>
+ <version>3.10.750-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml
index 71cb2981a5..f3fd207c78 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -169,6 +169,36 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-13</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-13</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13</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 28d1790c30..2423bcf082 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
@@ -3549,22 +3549,22 @@ public void testBug531714_001() {
" default -> 3;\n" +
" };\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The preview feature Switch Expressions is only available with source level 12 and above\n" +
+ "The preview feature Switch Expressions is only available with source level 13 and above\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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
runComplianceParserTest(
@@ -3601,17 +3601,17 @@ public void testBug531714_002() {
"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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\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 12 and above\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
runComplianceParserTest(
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
index 9b78ee7553..789fd412dc 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
@@ -57,6 +57,7 @@ static {
// org.eclipse.jdt.internal.codeassist.CompletionEngine.DEBUG = true;
// TESTS_NUMBERS = new int[] { 8 };
// TESTS_RANGE = new int[] { 20, -1 };
+// TESTS_NAMES = new String[] { "test001" };
}
public static Test suite() {
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 7048f31f84..e9c12ebb8a 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
@@ -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
@@ -17,6 +17,7 @@ import java.util.Hashtable;
import java.util.Map;
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -753,6 +754,25 @@ public void test027() {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=239198
*/
public void test028() {
+ String error = (this.complianceLevel == ClassFileConstants.JDK13) ?
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " Srtring bar = \"\"\"\n" +
+ " }\n" +
+ " ^^^^^^^^^\n" +
+ "Text block is not properly closed with the delimiter\n" +
+ "----------\n" :
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " Srtring bar = \"\"\"\n" +
+ " ^^\n" +
+ "Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " Srtring bar = \"\"\"\n" +
+ " ^\n" +
+ "String literal is not properly closed by a double-quote\n" +
+ "----------\n";
Map options = getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR);
runNegativeTest(
@@ -765,17 +785,7 @@ public void test028() {
" }\n" +
"}"
},
- "----------\n" +
- "1. ERROR in X.java (at line 4)\n" +
- " Srtring bar = \"\"\"\n" +
- " ^^\n" +
- "Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 4)\n" +
- " Srtring bar = \"\"\"\n" +
- " ^\n" +
- "String literal is not properly closed by a double-quote\n" +
- "----------\n",
+ error,
null,
true,
options);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
index d8de1163d2..7912c9e4b6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java
@@ -500,11 +500,13 @@ public void test010() throws JavaModelException {
" public X() {\n" +
" }\n" +
" public static void foo(Num num_) {\n" +
- " {\n" +
- " {\n" +
- " int i_j;\n" +
- " <SelectOnName:i_j>;\n" +
- " }\n" +
+ " switch (num_) {\n" +
+ " case THREE ->\n" +
+ " {\n" +
+ " int i_j;\n" +
+ " System.out.println(<SelectOnName:i_j>);\n" +
+ " break;\n" +
+ " }\n" +
" }\n" +
" }\n" +
"}\n";
@@ -786,285 +788,4 @@ public void test017() throws JavaModelException {
checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
selectionIdentifier, expectedReplacedSource, testName);
}
-public void test018() throws JavaModelException {
- String string = "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m( Supplier< M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 1 -> this::n_1; \n" +
- " default -> this::n_2; }); \n" +
- " }\n" +
- "}";
-
- String selection = "n_1";
- String selectKey = "<SelectionOnReferenceExpressionName:this::";
- String expectedSelection = selectKey + selection + ">";
-
- String selectionIdentifier = "n_1";
- String expectedUnitDisplayString =
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {\n" +
- "}\n" +
- "interface IN1 extends IN0 {\n" +
- "}\n" +
- "interface IN2 extends IN0 {\n" +
- "}\n" +
- "public class X {\n" +
- " public X() {\n" +
- " }\n" +
- " IN1 n_1() {\n" +
- " }\n" +
- " IN2 n_2() {\n" +
- " }\n" +
- " <M>void m(Supplier<M> m2) {\n" +
- " }\n" +
- " void testSw(int i) {\n" +
- " m(switch (i) {\n" +
- "case 1 ->\n" +
- " <SelectionOnReferenceExpressionName:this::n_1>;\n" +
- "default ->\n" +
- " this::n_2;\n" +
- "});\n" +
- " }\n" +
- "}\n";
- String expectedReplacedSource = "this::n_1";
- String testName = "X.java";
-
- int selectionStart = string.lastIndexOf(selection);
- int selectionEnd = selectionStart + selection.length() - 1;
-
- checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
- selectionIdentifier, expectedReplacedSource, testName);
-}
-public void test019() throws JavaModelException {
- String string = "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m( Supplier< M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " case 2 -> () -> n_1(); \n" +
- " default -> this::n_2; }); \n" +
- " }\n" +
- "}";
-
- String selection = "n_1";
- String selectKey = "<SelectOnMessageSend:";
- String expectedSelection = selectKey + selection + "()>";
-
- String selectionIdentifier = "n_1";
- String expectedUnitDisplayString =
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {\n" +
- "}\n" +
- "interface IN1 extends IN0 {\n" +
- "}\n" +
- "interface IN2 extends IN0 {\n" +
- "}\n" +
- "public class X {\n" +
- " public X() {\n" +
- " }\n" +
- " IN1 n_1() {\n" +
- " }\n" +
- " IN2 n_2() {\n" +
- " }\n" +
- " <M>void m(Supplier<M> m2) {\n" +
- " }\n" +
- " void testSw(int i) {\n" +
- " m(switch (i) {\n" +
- "case 2 ->\n" +
- " () -> <SelectOnMessageSend:n_1()>;\n" +
- "default ->\n" +
- " this::n_2;\n" +
- "});\n" +
- " }\n" +
- "}\n";
- String expectedReplacedSource = "n_1()";
- String testName = "X.java";
-
- int selectionStart = string.lastIndexOf(selection);
- int selectionEnd = selectionStart + selection.length() - 1;
-
- checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
- selectionIdentifier, expectedReplacedSource, testName);
-}
-public void test020() throws JavaModelException {
- String string = "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " IN1 n_1() { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m( Supplier< M> m2) { } \n" +
- " void testSw(int i) { \n" +
- " m(switch(i) { \n" +
- " default -> this::n_2; }); \n" +
- " }\n" +
- "}";
-
- String selection = "n_2";
- String selectKey = "<SelectionOnReferenceExpressionName:this::";
- String expectedSelection = selectKey + selection + ">";
-
- String selectionIdentifier = "n_2";
- String expectedUnitDisplayString =
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {\n" +
- "}\n" +
- "interface IN1 extends IN0 {\n" +
- "}\n" +
- "interface IN2 extends IN0 {\n" +
- "}\n" +
- "public class X {\n" +
- " public X() {\n" +
- " }\n" +
- " IN1 n_1() {\n" +
- " }\n" +
- " IN2 n_2() {\n" +
- " }\n" +
- " <M>void m(Supplier<M> m2) {\n" +
- " }\n" +
- " void testSw(int i) {\n" +
- " m(switch (i) {\n" +
- "default ->\n" +
- " <SelectionOnReferenceExpressionName:this::n_2>;\n" +
- "});\n" +
- " }\n" +
- "}\n";
- String expectedReplacedSource = "this::n_2";
- String testName = "X.java";
-
- int selectionStart = string.lastIndexOf(selection);
- int selectionEnd = selectionStart + selection.length() - 1;
-
- checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
- selectionIdentifier, expectedReplacedSource, testName);
-}
-public void test021() throws JavaModelException {
- String string = "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " IN1 n_1(int ijk) { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m( Supplier< M> m2) { } \n" +
- " void testSw(int ijk) { \n" +
- " m(switch(ijk) { \n" +
- " default -> () -> n_1(ijk); }); \n" +
- " }\n" +
- "}";
-
- String selection = "n_1";
- String selectKey = "<SelectOnMessageSend:";
- String expectedSelection = selectKey + selection + "(ijk)>";
-
- String selectionIdentifier = "n_1";
- String expectedUnitDisplayString =
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {\n" +
- "}\n" +
- "interface IN1 extends IN0 {\n" +
- "}\n" +
- "interface IN2 extends IN0 {\n" +
- "}\n" +
- "public class X {\n" +
- " public X() {\n" +
- " }\n" +
- " IN1 n_1(int ijk) {\n" +
- " }\n" +
- " IN2 n_2() {\n" +
- " }\n" +
- " <M>void m(Supplier<M> m2) {\n" +
- " }\n" +
- " void testSw(int ijk) {\n" +
- " m(switch (ijk) {\n" +
- "default ->\n" +
- " () -> <SelectOnMessageSend:n_1(ijk)>;\n" +
- "});\n" +
- " }\n" +
- "}\n";
- String expectedReplacedSource = "n_1(ijk)";
- String testName = "X.java";
-
- int selectionStart = string.lastIndexOf(selection);
- int selectionEnd = selectionStart + selection.length() - 1;
-
- checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
- selectionIdentifier, expectedReplacedSource, testName);
-}
-public void test022() throws JavaModelException {
- String string = "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {} \n" +
- "interface IN1 extends IN0 {} \n" +
- "interface IN2 extends IN0 {}\n" +
- "public class X {\n" +
- " IN1 n_1(int ijk) { return new IN1() {}; } \n" +
- " IN2 n_2() { return null; } \n" +
- " <M> void m( Supplier< M> m2) { } \n" +
- " void testSw(int ijk) { \n" +
- " m(switch(ijk) { \n" +
- " default -> () -> n_1(ijk); }); \n" +
- " }\n" +
- "}";
-
- String selection = "ijk";
- String selectKey = "<SelectOnName:";
- String expectedSelection = selectKey + selection + ">";
-
- String selectionIdentifier = "ijk";
- String expectedUnitDisplayString =
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.function.*;\n" +
- "interface IN0 {\n" +
- "}\n" +
- "interface IN1 extends IN0 {\n" +
- "}\n" +
- "interface IN2 extends IN0 {\n" +
- "}\n" +
- "public class X {\n" +
- " public X() {\n" +
- " }\n" +
- " IN1 n_1(int ijk) {\n" +
- " }\n" +
- " IN2 n_2() {\n" +
- " }\n" +
- " <M>void m(Supplier<M> m2) {\n" +
- " }\n" +
- " void testSw(int ijk) {\n" +
- " m(switch (ijk) {\n" +
- "default ->\n" +
- " () -> n_1(<SelectOnName:ijk>);\n" +
- "});\n" +
- " }\n" +
- "}\n";
- String expectedReplacedSource = "ijk";
- String testName = "X.java";
-
- int selectionStart = string.lastIndexOf(selection);
- int selectionEnd = selectionStart + selection.length() - 1;
-
- checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
- selectionIdentifier, expectedReplacedSource, testName);
-}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest13.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest13.java
new file mode 100644
index 0000000000..854d12db87
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest13.java
@@ -0,0 +1,1070 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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.compiler.parser;
+
+import org.eclipse.jdt.core.JavaModelException;
+
+import junit.framework.Test;
+
+public class SelectionParserTest13 extends AbstractSelectionTest {
+static {
+// TESTS_NUMBERS = new int[] { 1 };
+// TESTS_NAMES = new String[] { "test005" };
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(SelectionParserTest13.class, F_13);
+}
+
+public SelectionParserTest13(String testName) {
+ super(testName);
+}
+/*
+ * Multi constant case statement with ':', selection node is the string constant
+ */
+public void test001() throws JavaModelException {
+ String string = "public class X {\n" +
+ "static final String ONE=\"One\", TWO = \"Two\", THREE=\"Three\";\n" +
+ " public static void foo(String num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE:\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "ONE";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "ONE";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " static final String ONE;\n" +
+ " static final String TWO;\n" +
+ " static final String THREE;\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(String num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:ONE> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "ONE";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with ':', selection node is the first enum constant
+ */
+public void test002() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE:\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "ONE";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "ONE";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:ONE> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "ONE";
+ String testName = "X.java";
+
+ int selectionStart = string.indexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with ':', selection node is the second string constant
+ */
+public void test003() throws JavaModelException {
+ String string = "public class X {\n" +
+ "static final String ONE=\"One\", TWO = \"Two\", THREE=\"Three\";\n" +
+ " public static void foo(String num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE:\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "TWO";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "TWO";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " static final String ONE;\n" +
+ " static final String TWO;\n" +
+ " static final String THREE;\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(String num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:TWO> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "TWO";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with ':', selection node is the second enum constant
+ */
+public void test004() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE:\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "TWO";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "TWO";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:TWO> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "TWO";
+ String testName = "X.java";
+
+ int selectionStart = string.indexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection node is the string constant
+ */
+public void test005() throws JavaModelException {
+ String string = "public class X {\n" +
+ "static final String ONE=\"One\", TWO = \"Two\", THREE=\"Three\";\n" +
+ " public static void foo(String num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE ->\n" +
+ " System.out.println(num);\n" +
+ " }" +
+ " }\n" +
+ "}";
+ /*
+ * Note: The completion parser ignores the -> that follows and we end up creating
+ * the CaseStatement without maring it as an Expression, hence the ':' instead of the '->'
+ */
+ String selection = "ONE";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+ String selectionIdentifier = "ONE";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " static final String ONE;\n" +
+ " static final String TWO;\n" +
+ " static final String THREE;\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(String num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:ONE> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "ONE";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection node is the first enum constant
+ */
+public void test006() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE ->\n" +
+ " System.out.println(num);\n" +
+ " break; // illegal, but should be ignored and shouldn't matter\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "ONE";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "ONE";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:ONE> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "ONE";
+ String testName = "X.java";
+
+ int selectionStart = string.indexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection node is the second string constant
+ */
+public void test007() throws JavaModelException {
+ String string = "public class X {\n" +
+ "static final String ONE=\"One\", TWO = \"Two\", THREE=\"Three\";\n" +
+ " public static void foo(String num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE ->\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "TWO";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "TWO";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " static final String ONE;\n" +
+ " static final String TWO;\n" +
+ " static final String THREE;\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(String num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:TWO> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "TWO";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection node is the second enum constant
+ */
+public void test008() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num) {\n" +
+ " switch (num) {\n" +
+ " case ONE, TWO, THREE ->\n" +
+ " System.out.println(num);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "TWO";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "TWO";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num) {\n" +
+ " {\n" +
+ " switch (num) {\n" +
+ " case <SelectOnName:TWO> :\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "TWO";
+ String testName = "X.java";
+
+ int selectionStart = string.indexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a reference in the case block
+ * which same as the switch's expression
+ */
+public void test009() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num_) {\n" +
+ " switch (num_) {\n" +
+ " case ONE, TWO, THREE ->\n" +
+ " System.out.println(num_);\n" +
+ " break;\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num_) {\n" +
+ " {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a reference in the case block
+ * which is referencing a local variable defined in the case block
+ */
+public void test010() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num_) {\n" +
+ " switch (num_) {\n" +
+ " case ONE, TWO, THREE -> {\n" +
+ " int i_j = 0;" +
+ " System.out.println(i_j);\n" +
+ " break;" +
+ " }\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "i_j";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "i_j";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num_) {\n" +
+ " {\n" +
+ " {\n" +
+ " int i_j;\n" +
+ " <SelectOnName:i_j>;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "i_j";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type enum in switch expression
+ */
+public void test011() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(Num num_) {\n" +
+ " switch (num_) {\n" +
+ " case ONE, TWO, THREE -> {\n" +
+ " break;" +
+ " }\n" +
+ " }" +
+ " }\n" +
+ " enum Num { ONE, TWO, THREE;}\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " enum Num {\n" +
+ " ONE(),\n" +
+ " TWO(),\n" +
+ " THREE(),\n" +
+ " <clinit>() {\n" +
+ " }\n" +
+ " Num() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(Num num_) {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test012() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(int num_) {\n" +
+ " switch (num_ + 1) {\n" +
+ " case 1, 2, 3 -> {\n" +
+ " break;" +
+ " }\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(int num_) {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test013() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(int num_) {\n" +
+ " int i = switch (num_) {\n" +
+ " case 1, 2, 3 -> (num_ + 1);\n" +
+ " default -> 0;\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(int num_) {\n" +
+ " int i;\n" +
+ " {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test014() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(int num_) {\n" +
+ " int i = switch (num_) {\n" +
+ " case 1, 2, 3 -> 0;\n" +
+ " default -> (num_ + 1);\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(int num_) {\n" +
+ " int i;\n" +
+ " {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test015() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public static void foo(int num_) {\n" +
+ " int i = switch (num_) {\n" +
+ " case 1, 2, 3 -> 0;\n" +
+ " default -> (num_ + 1);\n" +
+ " }" +
+ " }\n" +
+ "}";
+
+ String selection = "num_";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "num_";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public static void foo(int num_) {\n" +
+ " int i;\n" +
+ " {\n" +
+ " <SelectOnName:num_>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "num_";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test016() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public void bar(int s) {\n" +
+ " int i_j = switch (s) {\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " default -> i_j;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n";
+
+ String selection = "i_j";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "i_j";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public void bar(int s) {\n" +
+ " int i_j;\n" +
+ " {\n" +
+ " <SelectOnName:i_j>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "i_j";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test017() throws JavaModelException {
+ String string = "public class X {\n" +
+ " public void bar(int s) {\n" +
+ " int i_j = switch (s) {\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " default -> (1+i_j);\n" +
+ " };\n" +
+ " }\n" +
+ "}\n";
+
+ String selection = "i_j";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "i_j";
+ String expectedUnitDisplayString =
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " public void bar(int s) {\n" +
+ " int i_j;\n" +
+ " {\n" +
+ " <SelectOnName:i_j>;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "i_j";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test018() throws JavaModelException {
+ String string = "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m( Supplier< M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> this::n_1; \n" +
+ " default -> this::n_2; }); \n" +
+ " }\n" +
+ "}";
+
+ String selection = "n_1";
+ String selectKey = "<SelectionOnReferenceExpressionName:this::";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "n_1";
+ String expectedUnitDisplayString =
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {\n" +
+ "}\n" +
+ "interface IN1 extends IN0 {\n" +
+ "}\n" +
+ "interface IN2 extends IN0 {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " IN1 n_1() {\n" +
+ " }\n" +
+ " IN2 n_2() {\n" +
+ " }\n" +
+ " <M>void m(Supplier<M> m2) {\n" +
+ " }\n" +
+ " void testSw(int i) {\n" +
+ " m(switch (i) {\n" +
+ "case 1 ->\n" +
+ " <SelectionOnReferenceExpressionName:this::n_1>;\n" +
+ "default ->\n" +
+ " this::n_2;\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "this::n_1";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test019() throws JavaModelException {
+ String string = "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m( Supplier< M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 2 -> () -> n_1(); \n" +
+ " default -> this::n_2; }); \n" +
+ " }\n" +
+ "}";
+
+ String selection = "n_1";
+ String selectKey = "<SelectOnMessageSend:";
+ String expectedSelection = selectKey + selection + "()>";
+
+ String selectionIdentifier = "n_1";
+ String expectedUnitDisplayString =
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {\n" +
+ "}\n" +
+ "interface IN1 extends IN0 {\n" +
+ "}\n" +
+ "interface IN2 extends IN0 {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " IN1 n_1() {\n" +
+ " }\n" +
+ " IN2 n_2() {\n" +
+ " }\n" +
+ " <M>void m(Supplier<M> m2) {\n" +
+ " }\n" +
+ " void testSw(int i) {\n" +
+ " m(switch (i) {\n" +
+ "case 2 ->\n" +
+ " () -> <SelectOnMessageSend:n_1()>;\n" +
+ "default ->\n" +
+ " this::n_2;\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "n_1()";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test020() throws JavaModelException {
+ String string = "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m( Supplier< M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " default -> this::n_2; }); \n" +
+ " }\n" +
+ "}";
+
+ String selection = "n_2";
+ String selectKey = "<SelectionOnReferenceExpressionName:this::";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "n_2";
+ String expectedUnitDisplayString =
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {\n" +
+ "}\n" +
+ "interface IN1 extends IN0 {\n" +
+ "}\n" +
+ "interface IN2 extends IN0 {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " IN1 n_1() {\n" +
+ " }\n" +
+ " IN2 n_2() {\n" +
+ " }\n" +
+ " <M>void m(Supplier<M> m2) {\n" +
+ " }\n" +
+ " void testSw(int i) {\n" +
+ " m(switch (i) {\n" +
+ "default ->\n" +
+ " <SelectionOnReferenceExpressionName:this::n_2>;\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "this::n_2";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test021() throws JavaModelException {
+ String string = "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " IN1 n_1(int ijk) { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m( Supplier< M> m2) { } \n" +
+ " void testSw(int ijk) { \n" +
+ " m(switch(ijk) { \n" +
+ " default -> () -> n_1(ijk); }); \n" +
+ " }\n" +
+ "}";
+
+ String selection = "n_1";
+ String selectKey = "<SelectOnMessageSend:";
+ String expectedSelection = selectKey + selection + "(ijk)>";
+
+ String selectionIdentifier = "n_1";
+ String expectedUnitDisplayString =
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {\n" +
+ "}\n" +
+ "interface IN1 extends IN0 {\n" +
+ "}\n" +
+ "interface IN2 extends IN0 {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " IN1 n_1(int ijk) {\n" +
+ " }\n" +
+ " IN2 n_2() {\n" +
+ " }\n" +
+ " <M>void m(Supplier<M> m2) {\n" +
+ " }\n" +
+ " void testSw(int ijk) {\n" +
+ " m(switch (ijk) {\n" +
+ "default ->\n" +
+ " () -> <SelectOnMessageSend:n_1(ijk)>;\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "n_1(ijk)";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+public void test022() throws JavaModelException {
+ String string = "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " IN1 n_1(int ijk) { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m( Supplier< M> m2) { } \n" +
+ " void testSw(int ijk) { \n" +
+ " m(switch(ijk) { \n" +
+ " default -> () -> n_1(ijk); }); \n" +
+ " }\n" +
+ "}";
+
+ String selection = "ijk";
+ String selectKey = "<SelectOnName:";
+ String expectedSelection = selectKey + selection + ">";
+
+ String selectionIdentifier = "ijk";
+ String expectedUnitDisplayString =
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {\n" +
+ "}\n" +
+ "interface IN1 extends IN0 {\n" +
+ "}\n" +
+ "interface IN2 extends IN0 {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public X() {\n" +
+ " }\n" +
+ " IN1 n_1(int ijk) {\n" +
+ " }\n" +
+ " IN2 n_2() {\n" +
+ " }\n" +
+ " <M>void m(Supplier<M> m2) {\n" +
+ " }\n" +
+ " void testSw(int ijk) {\n" +
+ " m(switch (ijk) {\n" +
+ "default ->\n" +
+ " () -> n_1(<SelectOnName:ijk>);\n" +
+ "});\n" +
+ " }\n" +
+ "}\n";
+ String expectedReplacedSource = "ijk";
+ String testName = "X.java";
+
+ int selectionStart = string.lastIndexOf(selection);
+ int selectionEnd = selectionStart + selection.length() - 1;
+
+ checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
+ selectionIdentifier, expectedReplacedSource, testName);
+}
+}
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 8699a67c45..5f0c5c3b34 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
@@ -207,6 +207,28 @@ public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) {
TestCase.RUN_ONLY_ID = null;
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12), tests_12));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_13) != 0) {
+ ArrayList tests_13 = (ArrayList)testClasses.clone();
+ tests_13.addAll(TEST_CLASSES_1_5);
+ tests_13.add(ParserTest1_7.class);
+ tests_13.add(LambdaExpressionSyntaxTest.class);
+ tests_13.add(ReferenceExpressionSyntaxTest.class);
+ tests_13.add(TypeAnnotationSyntaxTest.class);
+ tests_13.add(CompletionParserTest18.class);
+ tests_13.add(SelectionParserTest18.class);
+ tests_13.add(SelectionParserTest9.class);
+ tests_13.add(SelectionParserTest10.class);
+ tests_13.add(SelectionParserTest12.class);
+ tests_13.add(ModuleDeclarationSyntaxTest.class);
+ tests_13.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_13), tests_13));
+ }
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 31f5fb6c72..55553d1ffd 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
@@ -302,6 +302,8 @@ static class JavacCompiler {
return JavaCore.VERSION_11;
} else if(rawVersion.startsWith("12")) {
return JavaCore.VERSION_12;
+ } else if(rawVersion.startsWith("13")) {
+ return JavaCore.VERSION_13;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
@@ -423,6 +425,20 @@ static class JavacCompiler {
return 0200;
}
}
+ if (version == JavaCore.VERSION_13) {
+ if ("13-ea".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("13".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("13.0.1".equals(rawVersion)) {
+ return 0100;
+ }
+ if ("13.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
@@ -565,6 +581,20 @@ protected static class JavacTestOptions {
throw new IllegalArgumentException("preview not supported at release "+release);
return options;
}
+ @java.lang.SuppressWarnings("synthetic-access")
+ static JavacTestOptions forReleaseWithPreview(String release, String additionalOptions) {
+ JavacTestOptions options = new JavacTestOptions(Long.parseLong(release));
+ if (isJRE9Plus) {
+ String result = "--release "+release+" --enable-preview -Xlint:-preview";
+ if (additionalOptions != null)
+ result = result + " " + additionalOptions;
+ options.setCompilerOptions(result);
+
+ }
+ else
+ throw new IllegalArgumentException("preview not supported at release "+release);
+ return options;
+ }
public static class SuppressWarnings extends JavacTestOptions {
public SuppressWarnings(String token) {
setCompilerOptions("-Xlint:-"+token);
@@ -947,7 +977,7 @@ protected static class JavacTestOptions {
JavacBug8144832 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8144832
new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK9, 0000) : null,
JavacBug8179483_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8179483
- new JavacBug8179483(" --release 12 --enable-preview -Xlint:-preview") : null,
+ new JavacBug8179483(" --release 13 --enable-preview -Xlint:-preview") : null,
JavacBug8221413_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8221413
new JavacBug8221413(" --release 12 --enable-preview -Xlint:-preview") : null,
JavacBug8226510_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8226510
@@ -1759,7 +1789,7 @@ protected static class JavacTestOptions {
skipJavac ? JavacTestOptions.SKIP :
javacTestOptions != null ? javacTestOptions : JavacTestOptions.DEFAULT /* default javac test options */);
}
- protected void runConformTest(String[] testFiles, Map customOptions) {
+ protected void runConformTest(String[] testFiles, Map<String, String> customOptions) {
runTest(
// test directory preparation
true /* flush output directory */,
@@ -1781,10 +1811,10 @@ protected static class JavacTestOptions {
// javac options
JavacTestOptions.DEFAULT /* default javac test options */);
}
- protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
runConformTest(testFiles, expectedOutput, customOptions, null);
}
- protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments) {
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments) {
runTest(
// test directory preparation
true /* flush output directory */,
@@ -1865,7 +1895,7 @@ protected static class JavacTestOptions {
String[] classLibraries,
boolean shouldFlushOutputDirectory,
String[] vmArguments,
- Map customOptions,
+ Map<String, String> customOptions,
ICompilerRequestor customRequestor) {
runTest(
// test directory preparation
@@ -2951,7 +2981,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
String[] testFiles,
// compiler options
String[] classLibraries,
- Map customOptions,
+ Map<String, String> customOptions,
boolean performStatementsRecovery,
ICompilerRequestor customRequestor,
// compiler results
@@ -3091,7 +3121,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
// compiler options
String[] classLibraries,
boolean libsOnModulePath,
- Map customOptions,
+ Map<String, String> customOptions,
boolean performStatementsRecovery,
ICompilerRequestor customRequestor,
// compiler results
@@ -3126,7 +3156,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
requestor.outputPath = OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator;
// WORK should not have to test a constant?
- Map options = getCompilerOptions();
+ Map<String, String> options = getCompilerOptions();
if (customOptions != null) {
options.putAll(customOptions);
}
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 4d3f57f1ed..342f50c582 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
@@ -299,7 +299,7 @@ public class CompilerInvocationTests extends AbstractRegressionTest {
// templates, which can occur downstream in the localization process (assuming
// that we always release the English version right)
public void test009_missing_message_templates() {
- assertEquals("Unable to retrieve the error message for problem id: 4194303. Check compiler resources.",
+ assertEquals("Unable to retrieve the error message for problem id: 2097151. Check compiler resources.",
new DefaultProblemFactory().getLocalizedMessage(Integer.MAX_VALUE, new String[] {}));
}
@@ -807,6 +807,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("MissingTypeInConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("MissingTypeInLambda", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
+ expectedProblemAttributes.put("UnterminatedTextBlock", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("MissingTypeInMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("MissingValueForAnnotationMember", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("MissingValueFromLambda", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
@@ -1180,7 +1181,27 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("PreviewFeatureDisabled", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE));
expectedProblemAttributes.put("PreviewFeatureUsed", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE));
expectedProblemAttributes.put("PreviewFeatureNotSupported", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE));
- StringBuffer failures = new StringBuffer();
+ 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));
+ StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
Arrays.sort(fields, new Comparator() {
@@ -1757,6 +1778,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD));
expectedProblemAttributes.put("MissingTypeInConstructor", SKIP);
expectedProblemAttributes.put("MissingTypeInLambda", SKIP);
+ expectedProblemAttributes.put("UnterminatedTextBlock", SKIP);
expectedProblemAttributes.put("MissingTypeInMethod", SKIP);
expectedProblemAttributes.put("MissingValueForAnnotationMember", SKIP);
expectedProblemAttributes.put("MissingValueFromLambda", SKIP);
@@ -2130,7 +2152,27 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("PreviewFeatureDisabled", SKIP);
expectedProblemAttributes.put("PreviewFeatureUsed", SKIP);
expectedProblemAttributes.put("PreviewFeatureNotSupported", SKIP);
- Map constantNamesIndex = new HashMap();
+ expectedProblemAttributes.put("PreviewFeaturesNotAllowed", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldIncompatibleResultExpressionTypes", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldEmptySwitchBlock", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldNoResultExpression", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionaYieldSwitchLabeledBlockCompletesNormally", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldLastStatementCompletesNormally", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldTrailingSwitchLabels", SKIP);
+ expectedProblemAttributes.put("SwitchPreviewMixedCase", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingDefaultCase", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingValue", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldMissingEnumConstantCase", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldIllegalLastStatement", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldBreakNotAllowed", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodWarning", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodError", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldOutsideSwitchExpression", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldRestrictedGeneralWarning", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", SKIP);
+ Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
Field field = fields[i];
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 b0514b8936..6fc90320ea 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
@@ -2904,19 +2904,19 @@ public void testBug537804_comment5() {
"The local variable action may not have been initialized\n" +
"----------\n");
}
-public void testBug542707_001() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_001() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
- " break k;\n" +
+ " yield k;\n" +
" ^\n" +
"The local variable k may not have been initialized\n" +
"----------\n" +
@@ -2934,10 +2934,10 @@ public void testBug542707_001() {
" int it = switch (i) { \n" +
" case 1 -> {\n" +
" k = 1;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" default -> {\n" +
- " break k;\n" +
+ " yield k;\n" +
" }\n" +
" };\n" +
" return k + it;\n" +
@@ -2959,13 +2959,13 @@ public void testBug542707_001() {
defaultOptions);
}
-public void testBug542707_002() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_002() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -2976,7 +2976,7 @@ public void testBug542707_002() {
"The final local variable k may already have been assigned\n" +
"----------\n" +
"2. ERROR in X.java (at line 11)\n" +
- " break k;\n" +
+ " yield k;\n" +
" ^\n" +
"The local variable k may not have been initialized\n" +
"----------\n";
@@ -2989,10 +2989,10 @@ public void testBug542707_002() {
" k = switch (i) { \n" +
" case 1 -> {\n" +
" k = 1;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" default -> {\n" +
- " break k;\n" +
+ " yield k;\n" +
" }\n" +
" };\n" +
" return k;\n" +
@@ -3016,13 +3016,13 @@ public void testBug542707_002() {
/*
* k is definitely assigned - no errors on that front.
*/
-public void testBug542707_003() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_003() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3041,15 +3041,15 @@ public void testBug542707_003() {
" int it = switch (i) { \n" +
" case 1 -> {\n" +
" k = 1;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" case 2 -> {\n" +
" k = 2;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" default -> {\n" +
" k = 3;\n" +
- " break k;\n" +
+ " yield k;\n" +
" }\n" +
" };\n" +
" return k;\n" +
@@ -3071,13 +3071,13 @@ public void testBug542707_003() {
true,
defaultOptions);
}
-public void testBug542707_004() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_004() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3111,15 +3111,15 @@ public void testBug542707_004() {
" int it = switch (i) { \n" +
" case 1 -> {\n" +
" k = 1;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" case 2 -> {\n" +
" k = 2;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" default -> {\n" +
" k = 3;\n" +
- " break k;\n" +
+ " yield k;\n" +
" }\n" +
" };\n" +
" return k;\n" +
@@ -3141,19 +3141,19 @@ public void testBug542707_004() {
true,
defaultOptions);
}
-public void testBug542707_005() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_005() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" ^\n" +
"The local variable k may not have been initialized\n" +
"----------\n" +
@@ -3176,14 +3176,14 @@ public void testBug542707_005() {
" int it = switch (i) { \n" +
" case 1 -> {\n" +
" k = 1;\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" case 2 -> {\n" +
- " break k ;\n" +
+ " yield k ;\n" +
" }\n" +
" default -> {\n" +
" k = 3;\n" +
- " break k;\n" +
+ " yield k;\n" +
" }\n" +
" };\n" +
" return k;\n" +
@@ -3206,20 +3206,20 @@ public void testBug542707_005() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
- * V is definitely assigned after a switch expression when true iff for every value break statement with
+ * V is definitely assigned after a switch expression when true iff for every value yield statement with
* expression e in the switch block that may exit the switch expression, V is definitely assigned after e when true.
- * V is definitely assigned after a switch expression when false iff for every value break statement with
+ * V is definitely assigned after a switch expression when false iff for every value yield statement with
* expression e in the switch block that may exit the switch expression, V is definitely assigned after e when false.
*/
-public void testBug542707_006() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_006() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3237,14 +3237,14 @@ public void testBug542707_006() {
" boolean b = switch (i) {\n" +
" case 1 :\n" +
" v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3268,22 +3268,22 @@ public void testBug542707_006() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
- * V is definitely unassigned after a switch expression when true iff for every value break statement with expression
- * e in the switch block that may exit the switch expression, V is definitely unassigned before the value break
+ * V is definitely unassigned after a switch expression when true iff for every value yield statement with expression
+ * e in the switch block that may exit the switch expression, V is definitely unassigned before the value yield
* statement and V is definitely unassigned after e when true.
- * V is definitely unassigned after a switch expression when false iff for every value break statement with expression
- * e in the switch block that may exit the switch expression, V is definitely unassigned before the value break
+ * V is definitely unassigned after a switch expression when false iff for every value yield statement with expression
+ * e in the switch block that may exit the switch expression, V is definitely unassigned before the value yield
* statement and V is definitely unassigned after e when false.
*/
-public void testBug542707_007() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_007() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3306,14 +3306,14 @@ public void testBug542707_007() {
" boolean b = switch (i) {\n" +
" case 1 :\n" +
" //v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" //v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" //v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3337,17 +3337,17 @@ public void testBug542707_007() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
-public void testBug542707_008() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_008() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3365,14 +3365,14 @@ public void testBug542707_008() {
" boolean b = switch (i) {\n" +
" case 1 :\n" +
" //v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" //v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" //v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3396,17 +3396,17 @@ public void testBug542707_008() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
-public void testBug542707_009() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_009() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3429,14 +3429,14 @@ public void testBug542707_009() {
" boolean b = switch (v) {\n" +
" case 1 :\n" +
" v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3460,18 +3460,18 @@ public void testBug542707_009() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the first statement of the first switch labeled statement group in the switch block
* iff V is [un]assigned after the selector expression.
*/
-public void testBug542707_010() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_010() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3489,14 +3489,14 @@ public void testBug542707_010() {
" boolean b = switch (i + (v =1)) {\n" +
" case 1 :\n" +
" v += 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3520,18 +3520,18 @@ public void testBug542707_010() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the first statement of the first switch labeled statement group in the switch block
* iff V is [un]assigned after the selector expression.
*/
-public void testBug542707_011() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_011() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3554,14 +3554,14 @@ public void testBug542707_011() {
" boolean b = switch (i) {\n" +
" case 1 :\n" +
" v += 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3585,20 +3585,19 @@ public void testBug542707_011() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the first statement of any switch labeled statement group other than the first iff
* V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement.
- * TODO: the second part - "and V is [un]assigned after the preceding statement" needs to be checked, now it looks identical to the
- * preceding rule
+ * and V is [un]assigned after the preceding statement
*/
-public void testBug542707_012() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_012() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3616,14 +3615,14 @@ public void testBug542707_012() {
" boolean b = switch (i + (v =1)) {\n" +
" case 1 :\n" +
" v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v += 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3647,20 +3646,82 @@ public void testBug542707_012() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * which are boolean-valued.
+ * V is [un]assigned before the first statement of any switch labeled statement group other than the first iff
+ * V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement.
+ * and V is [un]assigned after the preceding statement"
+ */
+public void testBug548318_012b() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
+ 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);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 15)\n" +
+ " return v + d;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 19)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " int v;\n" +
+ " boolean b = switch (i) {\n" +
+ " case 1 :i =1;\n" +
+ " case 2 : {\n" +
+ " yield true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " yield false;\n" +
+ " }\n" +
+ " };\n" +
+ " int d = b == true ? 0 : 1; \n" +
+ " return v + d;\n" +
+ " }\n" +
+ "\n" +
+ " public boolean bar() {\n" +
+ " Zork();\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
+/**
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before the first statement of any switch labeled statement group other than the first iff
* V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement.
- * TODO: the second part - "and V is [un]assigned after the preceding statement" needs to be checked, now it looks identical to the
- * preceding rule
+ * and V is [un]assigned after the preceding statement" needs to be checked
*/
-public void testBug542707_013() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_013() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3683,14 +3744,14 @@ public void testBug542707_013() {
" boolean b = switch (i) {\n" +
" case 1 :\n" +
" v = 1;\n" +
- " break true;\n" +
+ " yield true;\n" +
" case 2 : {\n" +
" v += 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" default : {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" };\n" +
" int d = b == true ? 0 : 1; \n" +
@@ -3714,28 +3775,28 @@ public void testBug542707_013() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
* V is definitely assigned after a switch expression when true iff for every switch labeled rule one of the following is true:
* It is a switch labeled expression e and V is definitely assigned after e when true.
- * It is a switch labeled block b and for every value break statement expression e contained in b that may exit the switch expression,
+ * It is a switch labeled block b and for every value yield statement expression e contained in b that may exit the switch expression,
* V is definitely assigned after e when true.
* It is a switch labeled throw statement.
*
* V is definitely assigned after a switch expression when false iff for every switch labeled rule one of the following is true:
* It is a switch labeled expression e and V is definitely assigned after e when false.
- * It is a switch labeled block b and for every value break statement expression e contained in b that may exit the switch expression,
+ * It is a switch labeled block b and for every value yield statement expression e contained in b that may exit the switch expression,
* V is definitely assigned after e when false.
* It is a switch labeled throw statement.
*/
-public void testBug542707_014() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_014() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3756,11 +3817,11 @@ public void testBug542707_014() {
" case 1 -> (v = 1) == 0;\n" +
" case 2 -> {\n" +
" v = 2;\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" case 3 -> {\n" +
" v = 3;\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -3789,30 +3850,30 @@ public void testBug542707_014() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
* V is definitely unassigned after a switch expression when true iff for every switch labeled rule one of the following is true:
* It is a switch labeled expression e and V is definitely unassigned after e when true .
- * It is a switch labeled block b and for every value break statement expression e contained in b that
- * may exit the switch expression, V is definitely unassigned before the value break statement and
+ * It is a switch labeled block b and for every value yield statement expression e contained in b that
+ * may exit the switch expression, V is definitely unassigned before the value yield statement and
* V is definitely unassigned after e when true.
* It is a switch labeled throw statement.
*
* V is definitely unassigned after a switch expression when false iff for every switch labeled rule one of the following is true:
* It is a switch labeled expression e and V is definitely unassigned after e when false.
- * It is a switch labeled block b and for every value break statement expression e contained in b that may
- * exit the switch expression, V is definitely unassigned before the value break statement and V is definitely unassigned
+ * It is a switch labeled block b and for every value yield statement expression e contained in b that may
+ * exit the switch expression, V is definitely unassigned before the value yield statement and V is definitely unassigned
* after e when false.
* It is a switch labeled throw statement.
*/
-public void testBug542707_015() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_015() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3837,10 +3898,10 @@ public void testBug542707_015() {
" case 0 -> true;\n" +
" case 1 -> false;\n" +
" case 2 -> {\n" +
- " break true;\n" +
+ " yield true;\n" +
" }\n" +
" case 3 -> {\n" +
- " break false;\n" +
+ " yield false;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -3869,18 +3930,18 @@ public void testBug542707_015() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* V is [un]assigned before any switch labeled expression or statement in the switch
* block iff V is [un]assigned after the selector expression.
*/
-public void testBug542707_016() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_016() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3925,19 +3986,19 @@ public void testBug542707_016() {
defaultOptions);
}
/**
- * From JLS 12 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
+ * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of
* which are boolean-valued.
* The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
* V is [un]assigned before any switch labeled expression or statement in the switch
* block iff V is [un]assigned after the selector expression.
*/
-public void testBug542707_017() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_017() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -3992,21 +4053,18 @@ public void testBug542707_017() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
- * which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
- * V is definitely assigned after a switch expression iff for every value break statement with expression e
- * in the switch block that may exit the switch expression, either V is definitely assigned before the value
- * break statement or V is definitely assigned after e.
+ * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true:
+ * V is [un]assigned before every yield statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
*/
-public void testBug542707_018() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_018() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4023,14 +4081,14 @@ public void testBug542707_018() {
" int v;\n" +
" int t = switch (i) {\n" +
" case 0 : {\n" +
- " v = 1; // definitely assigned before break\n" +
- " break v;\n" +
+ " v = 1; // definitely assigned before yield\n" +
+ " yield v;\n" +
" }\n" +
" case 2 : {\n" +
- " break v =1; // definitely assigned after e\n" +
+ " yield v =1; // definitely assigned after e\n" +
" }\n" +
" default : {\n" +
- " break v = 2;\n" +
+ " yield v = 2;\n" +
" }\n" +
" };\n" +
" return v + t;\n" +
@@ -4053,21 +4111,18 @@ public void testBug542707_018() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
- * which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
- * V is definitely unassigned after a switch expression iff for every value break statement with expression e
- * in the switch block that may exit the switch expression, V is definitely unassigned before the value break
- * statement and V is definitely unassigned after e.
+ * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true:
+ * V is [un]assigned before every yield statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
*/
-public void testBug542707_019() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_019() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4089,13 +4144,13 @@ public void testBug542707_019() {
" int v;\n" +
" int t = switch (i) {\n" +
" case 0 : {\n" +
- " break 1;\n" +
+ " yield 1;\n" +
" }\n" +
" case 2 : {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return v + t;\n" +
@@ -4118,19 +4173,17 @@ public void testBug542707_019() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
-public void testBug542707_020() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_020() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4147,13 +4200,13 @@ public void testBug542707_020() {
" int v =1;\n" +
" int t = switch (v) {\n" +
" case 0 : {\n" +
- " break 1;\n" +
+ " yield 1;\n" +
" }\n" +
" case 2 : {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return t;\n" +
@@ -4176,19 +4229,17 @@ public void testBug542707_020() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
* V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
*/
-public void testBug542707_021() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_021() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4210,13 +4261,13 @@ public void testBug542707_021() {
" int v;\n" +
" int t = switch (v) {\n" +
" case 0 : {\n" +
- " break 1;\n" +
+ " yield 1;\n" +
" }\n" +
" case 2 : {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return t;\n" +
@@ -4239,20 +4290,21 @@ public void testBug542707_021() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
- * V is [un]assigned before the first statement of the first switch labeled statement group in the switch block
- * iff V is [un]assigned after the selector expression.
+ * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression
+ * iff both of following are true:
+ * V is [un]assigned after the selector expression of the switch statement.
+ * If the switch labeled statement group is not the first in the switch block,
+ * V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
-public void testBug542707_022() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_022() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4269,13 +4321,13 @@ public void testBug542707_022() {
" int v =1;\n" +
" int t = switch (v) {\n" +
" case 0 : {\n" +
- " break v;\n" +
+ " yield v;\n" +
" }\n" +
" case 2 : {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return t;\n" +
@@ -4298,26 +4350,27 @@ public void testBug542707_022() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
- * V is [un]assigned before the first statement of the first switch labeled statement group in the switch block
- * iff V is [un]assigned after the selector expression.
+ * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression
+ * iff both of following are true:
+ * V is [un]assigned after the selector expression of the switch statement.
+ * If the switch labeled statement group is not the first in the switch block,
+ * V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
-public void testBug542707_023() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_023() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
- " break v;\n" +
+ " yield v;\n" +
" ^\n" +
"The local variable v may not have been initialized\n" +
"----------\n" +
@@ -4333,13 +4386,13 @@ public void testBug542707_023() {
" int v;\n" +
" int t = switch (i) {\n" +
" case 0 : {\n" +
- " break v;\n" +
+ " yield v;\n" +
" }\n" +
" case 2 : {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return t;\n" +
@@ -4362,26 +4415,27 @@ public void testBug542707_023() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression (15.28) consists of switch
- * labeled statement groups:
- * V is [un]assigned before the first statement of any switch labeled statement group other than the first iff V is [un]assigned
- * after the selector expression and V is [un]assigned after the preceding statement.
+ * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression
+ * iff both of following are true:
+ * V is [un]assigned after the selector expression of the switch statement.
+ * If the switch labeled statement group is not the first in the switch block,
+ * V is [un]assigned after the last block statement of the preceding switch labeled statement group.
*/
-public void testBug542707_024() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_024() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
- " break v;\n" +
+ " yield v;\n" +
" ^\n" +
"The local variable v may not have been initialized\n" +
"----------\n" +
@@ -4397,13 +4451,13 @@ public void testBug542707_024() {
" int v ;\n" +
" int t = switch (i) {\n" +
" case 0 : {\n" +
- " break 1;\n" +
+ " yield 1;\n" +
" }\n" +
" case 2 : {\n" +
- " break v;\n" +
+ " yield v;\n" +
" }\n" +
" default : {\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" };\n" +
" return t;\n" +
@@ -4426,23 +4480,18 @@ public void testBug542707_024() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
- * which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
- * V is definitely assigned after a switch expression iff for every switch labeled rule one of the following is true:
- * It is a switch labeled expression e and V is definitely assigned after e.
- * It is a switch labeled block b and for every value break statement expression e contained in b that may exit
- * the switch expression, either V is definitely assigned before the value break statement or V is definitely
- * assigned after e.
- * It is a switch labeled throw statement.
+ * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true:
+ * V is [un]assigned before every yield statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
*/
-public void testBug542707_025() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_025() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4463,9 +4512,9 @@ public void testBug542707_025() {
" case 0 -> v = 1;\n" +
" case 2 -> {\n" +
" if (i > 1) {\n" +
- " break v = 2;\n" +
+ " yield v = 2;\n" +
" }\n" +
- " break v = 3;\n" +
+ " yield v = 3;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -4494,23 +4543,18 @@ public void testBug542707_025() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
- * which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
- * V is definitely unassigned after a switch expression iff for every switch labeled rule one of the following is true:
- * It is a switch labeled expression e and V is definitely unassigned after e.
- * It is a switch labeled block b and for every value break statement expression e contained in b that may exit the
- * switch expression, V is definitely unassigned before the value break statement
- * and V is definitely unassigned after e.
- * It is a switch labeled throw statement.
+ * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true:
+ * V is [un]assigned before every yield statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
*/
-public void testBug542707_026() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_026() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4536,9 +4580,9 @@ public void testBug542707_026() {
" case 0 -> 1;\n" +
" case 2 -> {\n" +
" if (i > 1) {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -4567,19 +4611,18 @@ public void testBug542707_026() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
- * V is [un]assigned before any switch labeled expression or statement in the switch block iff
- * V is [un]assigned after the selector expression.
+ * V is [un]assigned before the expression, block, or throw statement of a switch labeled rule of a
+ * switch expression iff V is [un]assigned after the selector expression of the switch expression.
*/
-public void testBug542707_027() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_027() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4600,9 +4643,9 @@ public void testBug542707_027() {
" case 0 -> v;\n" +
" case 2 -> {\n" +
" if (i > 1) {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -4631,19 +4674,18 @@ public void testBug542707_027() {
defaultOptions);
}
/**
- * From JLS 12 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
+ * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of
* which are boolean-valued.
- * The following rules apply only if the switch block of a switch expression consists of switch labeled rules:
- * V is [un]assigned before any switch labeled expression or statement in the switch block iff
- * V is [un]assigned after the selector expression.
+ * V is [un]assigned before the expression, block, or throw statement of a switch labeled rule of a
+ * switch expression iff V is [un]assigned after the selector expression of the switch expression.
*/
-public void testBug542707_028() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_028() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
@@ -4669,9 +4711,9 @@ public void testBug542707_028() {
" case 0 -> v;\n" +
" case 2 -> {\n" +
" if (i > 1) {\n" +
- " break 2;\n" +
+ " yield 2;\n" +
" }\n" +
- " break 3;\n" +
+ " yield 3;\n" +
" }\n" +
" default -> throw new IOException();\n" +
" };\n" +
@@ -4700,25 +4742,28 @@ public void testBug542707_028() {
defaultOptions);
}
/**
- * From JLS 12 16.2.9, The following rules apply only if the switch block of the switch statement consists of switch labeled rules:
- * V is [un]assigned after a switch statement iff for every switch labeled rule one of the following is true:
- * It is a switch labeled expression e and either V is [un]assigned after e or after the selector expression.
- * It is a switch labeled block b and either V is [un]assigned after e or V is [un]assigned before every
- * break statement contained in b that may exit the switch statement.
- * It is a switch labeled throw statement.
+ * From JLS 13 16.2.9, [tests the second rule - assigned]
+ * V is [un]assigned after a switch statement (14.11) iff all of the following are true:
+ * V is [un]assigned before every break statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
+ * If there is a switch labeled statement group (14.11.1) in the switch block, then V is [un]assigned
+ * after the last block statement of the last switch labeled statement group.
+ * If there is no default label in the switch block, or if the switch block ends with a switch label
+ * followed by }, then V is [un]assigned after the selector expression
*/
-public void testBug542707_029() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_029() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
"----------\n" +
- "2. ERROR in X.java (at line 24)\n" +
+ "1. ERROR in X.java (at line 24)\n" +
" Zork();\n" +
" ^^^^\n" +
"The method Zork() is undefined for the type X\n" +
@@ -4769,20 +4814,23 @@ public void testBug542707_029() {
defaultOptions);
}
/**
- * From JLS 12 16.2.9, The following rules apply only if the switch block of the switch statement consists of switch labeled rules:
- * V is [un]assigned after a switch statement iff for every switch labeled rule one of the following is true:
- * It is a switch labeled expression e and either V is [un]assigned after e or after the selector expression.
- * It is a switch labeled block b and either V is [un]assigned after e or V is [un]assigned before every
- * break statement contained in b that may exit the switch statement.
- * It is a switch labeled throw statement.
+ * From JLS 13 16.2.9, [tests the second rule - unassigned]
+ * V is [un]assigned after a switch statement (14.11) iff all of the following are true:
+ * V is [un]assigned before every break statement that may exit the switch statement.
+ * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the
+ * expression, block, or throw statement of the switch labeled rule.
+ * If there is a switch labeled statement group (14.11.1) in the switch block, then V is [un]assigned
+ * after the last block statement of the last switch labeled statement group.
+ * If there is no default label in the switch block, or if the switch block ends with a switch label
+ * followed by }, then V is [un]assigned after the selector expression
*/
-public void testBug542707_030() {
- if (this.complianceLevel != ClassFileConstants.JDK12)
+public void testBug548318_030() {
+ if (this.complianceLevel != ClassFileConstants.JDK13)
return;
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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);
String expectedProblemLog =
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java
index 4d1d261c6b..466ee9ce15 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java
@@ -69,7 +69,6 @@ static {
simpleTypeNames.put("ComparableAny", "Comparable<?>");
simpleTypeNames.put("CollectionExt_ComparableAny", "Collection<? extends Comparable<?>>");
simpleTypeNames.put("CollectionSuperComparableAny", "Collection<? super Comparable<?>>");
- isJRE12Plus = isJRELevel(F_12);
if (isJRE12Plus)
simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable<?> & java.lang.constant.Constable & java.lang.constant.ConstantDesc");
else
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 571e5f4400..6a62db3454 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
@@ -10404,15 +10404,10 @@ public void testBug542707_001() {
},
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 15)\n" +
- " default -> null;\n" +
- " ^^^^\n" +
- "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" +
+ "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" +
"----------\n"
);
}
@@ -10450,10 +10445,10 @@ public void testBug542707_002() {
},
options,
"----------\n" +
- "1. ERROR in X.java (at line 13)\n" +
- " Zork();\n" +
- " ^^^^\n" +
- "The method Zork() is undefined for the type X\n" +
+ "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" +
"----------\n"
);
}
@@ -10479,12 +10474,18 @@ public void testBug542707_003() {
" }\n" +
"}\n"
};
- runner.expectedCompilerLog =
+ runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
" default -> i == 3 ? maybe() : \"\";\n" +
" ^^^^^^^\n" +
- "Null type mismatch (type annotations): required '@NonNull String' but this expression has type '@Nullable String'\n" +
+ "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" +
+ "----------\n" :
+ "----------\n" +
+ "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" +
"----------\n";
runner.runNegativeTest();
}
@@ -10544,12 +10545,18 @@ public void testBug542707_005() {
" }\n" +
"}\n"
};
- runner.expectedCompilerLog =
+ runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" return switch(day) {\n" +
" ^^^\n" +
"Potential null pointer access: this expression has a \'@Nullable\' type\n" +
+ "----------\n" :
+ "----------\n" +
+ "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" +
"----------\n";
runner.runNegativeTest();
}
@@ -10575,17 +10582,23 @@ public void testBug542707_006() {
" }\n" +
"}\n"
};
- runner.expectedCompilerLog =
+ runner.expectedCompilerLog = this.complianceLevel == ClassFileConstants.JDK13 ?
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" return switch(day) {\n" +
" ^^^\n" +
"Potential null pointer access: The variable day may be null at this location\n" +
+ "----------\n" :
+ "----------\n" +
+ "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" +
"----------\n";
runner.runNegativeTest();
}
public void testBug545715() {
- if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ if (this.complianceLevel < ClassFileConstants.JDK13) 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);
@@ -10607,6 +10620,209 @@ public void testBug545715() {
customOptions,
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);
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import java.io.IOException;\n"+
+ "\n"+
+ "import org.eclipse.jdt.annotation.NonNull;\n"+
+ "\n"+
+ "public class X {\n"+
+ " public static int foo(int i) throws IOException {\n"+
+ " int k = 0;\n"+
+ " @NonNull\n"+
+ " X x = new X();\n"+
+ " x = switch (i) { \n"+
+ " case 1 -> {\n"+
+ " x = null;\n"+
+ " break x;\n"+
+ " }\n"+
+ " default -> null;\n"+
+ " };\n"+
+ "\n"+
+ " return k ;\n"+
+ " }\n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " try {\n"+
+ " System.out.println(foo(3));\n"+
+ " } catch (IOException e) {\n"+
+ " // do nothing\n"+
+ " }\n"+
+ " }\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" +
+ " 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" +
+ "----------\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);
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import java.io.IOException;\n"+
+ "\n"+
+ "import org.eclipse.jdt.annotation.NonNull;\n"+
+ "\n"+
+ "public class X {\n"+
+ " public static int foo(int i) throws IOException {\n"+
+ " int k = 0;\n"+
+ " @NonNull\n"+
+ " X x = new X();\n"+
+ " x = switch (i) { \n"+
+ " case 1 -> {\n"+
+ " x = null;\n"+
+ " yield x;\n"+
+ " }\n"+
+ " default -> null;\n"+
+ " };\n"+
+ "\n"+
+ " return k ;\n"+
+ " }\n"+
+ "\n"+
+ " public static void main(String[] args) {\n"+
+ " try {\n"+
+ " System.out.println(foo(3));\n"+
+ " } catch (IOException e) {\n"+
+ " // do nothing\n"+
+ " }\n"+
+ " }\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 15)\n" +
+ " default -> null;\n" +
+ " ^^^^\n" +
+ "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" +
+ "----------\n"
+ );
+}
+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);
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void m1(@NonNull String a) {}\n" +
+ " void m2(@Nullable String b, int i) {\n" +
+ " m1(switch(i) {\n" +
+ " case 0 : {\n" +
+ " break \"hello\";\n" +
+ " }\n" +
+ " default : break \"world\";\n" +
+ " });\n" +
+ " }\n" +
+ " void m3() {\n" +
+ " Zork();\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " break \"hello\";\n" +
+ " ^^^^^^^\n" +
+ "Syntax error on token \"\"hello\"\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " default : break \"world\";\n" +
+ " ^^^^^^^\n" +
+ "Syntax error on token \"\"world\"\", delete this token\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 13)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n"
+ );
+}
+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);
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " void m1(@NonNull String a) {}\n" +
+ " void m2(@Nullable String b, int i) {\n" +
+ " m1(switch(i) {\n" +
+ " case 0 : {\n" +
+ " yield \"hello\";\n" +
+ " }\n" +
+ " default : yield \"world\";\n" +
+ " });\n" +
+ " }\n" +
+ " void m3() {\n" +
+ " Zork();\n" +
+ " }\n" +
+ "}\n"
+ },
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 13)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n"
+ );
+}
public void testBug499714() {
runConformTestWithLibs(
new String[] {
@@ -10639,8 +10855,7 @@ public void testBug499714() {
"",
},
getCompilerOptions(),
- ""
- );
+ "");
}
public void testBug481931_source() {
runNegativeTestWithLibs(
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 76b77b3bca..d79f1ee407 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
@@ -5497,7 +5497,7 @@ public void testBug541705b() {
runner.runConformTest();
}
public void testBug542707_001() {
- if (this.complianceLevel < ClassFileConstants.JDK12) return; // uses switch expression
+ if (this.complianceLevel < ClassFileConstants.JDK13) 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);
@@ -5517,7 +5517,7 @@ public void testBug542707_001() {
" x = new X();\n"+
" x = switch (i) { \n"+
" case 1 -> {\n"+
- " break x;\n"+
+ " yield x;\n"+
" }\n"+
" default -> x;\n"+
" };\n"+
@@ -5549,7 +5549,7 @@ public void testBug542707_001() {
options);
}
public void testBug542707_002() {
- if (this.complianceLevel < ClassFileConstants.JDK12) return; // uses switch expression
+ if (this.complianceLevel < ClassFileConstants.JDK13) 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);
@@ -5570,7 +5570,7 @@ public void testBug542707_002() {
" x = switch (i) { \n"+
" case 1 -> {\n"+
" x = new X();\n"+
- " break x;\n"+
+ " yield x;\n"+
" }\n"+
" default -> x;\n"+
" };\n"+
@@ -5607,7 +5607,7 @@ public void testBug542707_002() {
options);
}
public void testBug542707_003() {
- if (this.complianceLevel < ClassFileConstants.JDK12) return; // uses switch expression
+ if (this.complianceLevel < ClassFileConstants.JDK13) 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);
@@ -5627,7 +5627,7 @@ public void testBug542707_003() {
" x = new X();\n"+
" x = switch (i) { \n"+
" case 1 -> {\n"+
- " break new X();\n"+
+ " yield new X();\n"+
" }\n"+
" default -> x;\n"+
" };\n"+
@@ -5654,7 +5654,7 @@ public void testBug542707_003() {
"1. ERROR in X.java (at line 10)\n" +
" x = switch (i) { \n" +
" case 1 -> {\n" +
- " break new X();\n" +
+ " yield new X();\n" +
" }\n" +
" default -> x;\n" +
" };\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
index 5959d4bff8..3f8bd30cc2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.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
@@ -1475,4 +1475,70 @@ public class ScannerTest extends AbstractRegressionTest {
});
}
}
+ public void testBug531716_001_since_13() {
+ char[] source = ("class X {\n" +
+ " String s = \"\"\"This is the new String\"\"\";\n" +
+ "}").toCharArray();
+ Scanner scanner = new Scanner(false, false, false, ClassFileConstants.getLatestJDKLevel(), null, null, false);
+ scanner.setSource(source);
+ scanner.resetTo(0, source.length - 1);
+ try {
+ int token;
+ StringBuffer buffer = new StringBuffer();
+ while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
+ try {
+ switch(token) {
+ case TerminalTokens.TokenNameTextBlock :
+ buffer.append( new String(scanner.getCurrentTextBlock()));
+ break;
+ case TerminalTokens.TokenNameStringLiteral :
+ break;
+ case TerminalTokens.TokenNameEOF :
+ break;
+ default :
+ break;
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ }
+ }
+ assertEquals("Wrong contents", "", String.valueOf(buffer));
+ } catch (InvalidInputException e) {
+ assertTrue(false);
+ }
+ }
+ public void testBug531716_001_since_13_1() {
+ char[] source = ("class X {\n" +
+ " String s = \"\"\"\nThis is the new String\"\"\";\n" +
+ "}").toCharArray();
+ Scanner scanner = new Scanner(false, false, false, ClassFileConstants.getLatestJDKLevel(), null, null, false);
+ scanner.previewEnabled = true;
+ scanner.setSource(source);
+ scanner.resetTo(0, source.length - 1);
+ try {
+ int token;
+ StringBuffer buffer = new StringBuffer();
+ while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
+ try {
+ switch(token) {
+ case TerminalTokens.TokenNameTextBlock :
+ buffer.append( new String(scanner.getCurrentTextBlock()));
+ break;
+ case TerminalTokens.TokenNameStringLiteral :
+ break;
+ case TerminalTokens.TokenNameEOF :
+ break;
+ default :
+ break;
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ }
+ }
+ assertEquals("Wrong contents", "This is the new String", String.valueOf(buffer));
+ } catch (InvalidInputException e) {
+ assertTrue(false);
+ }
+ }
+
}
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 fc14e13d23..1fef2d022a 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
@@ -14,7 +14,6 @@ package org.eclipse.jdt.core.tests.compiler.regression;
import java.util.Map;
-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;
@@ -47,38 +46,18 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
return defaultOptions;
}
-
+
@Override
- protected void runConformTest(String[] testFiles, String expectedOutput) {
- runConformTest(testFiles, expectedOutput, getCompilerOptions());
+ protected void runConformTest(String[] testFiles, Map<String, String> customOptions) {
+ super.runConformTest(testFiles, "", null, true, new String[] {"--enable-preview"}, customOptions, null);
}
@Override
- protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
- Runner runner = new Runner();
- runner.testFiles = testFiles;
- runner.expectedOutputString = expectedOutput;
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.customOptions = customOptions;
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("12");
- runner.runConformTest();
- }
- @Override
- protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
- runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("12"));
- }
- protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map<String, String> customOptions) {
- Runner runner = new Runner();
- runner.testFiles = testFiles;
- runner.expectedCompilerLog = expectedCompilerLog;
- runner.customOptions = customOptions;
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("12");
- runner.runWarningTest();
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
+ super.runConformTest(testFiles, expectedOutput, null, true, new String[] {"--enable-preview"}, customOptions, null);
}
-
public void testSimpleExpressions() {
- runConformTest(
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -95,10 +74,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
},
- "3");
+ "----------\n" +
+ "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" +
+ "----------\n");
}
public void testSwitchExpression_531714_002() {
- runConformTest(
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n"+
@@ -127,9 +111,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n"+
"}\n"
},
- "Got Exception - expected");
+ "----------\n" +
+ "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" +
+ "----------\n");
}
- public void testBug531714_error_003() {
+ public void _testBug531714_error_003() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -157,7 +146,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"A switch expression should have a default case\n" +
"----------\n");
}
- public void testBug531714_error_004() {
+ public void _testBug531714_error_004() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -180,13 +169,13 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 12)\n" +
- " case \"hello\" -> throw new java.io.IOException(\"hello\");\n" +
- " ^^^^^^^\n" +
- "Type mismatch: cannot convert from String to int\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " break 1;\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
"----------\n");
}
- public void testBug531714_error_005() {
+ public void _testBug531714_error_005() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -208,10 +197,10 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 6)\n" +
- " int tw = switch (i) {\n" +
- " ^\n" +
- "A switch expression should have a default case\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " break 1;\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
"----------\n");
}
/**
@@ -221,7 +210,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
* must contain all the enum constants of that enum type
* Add a missing enum test case
*/
- public void _testBug531714_error_006() {
+ public void __testBug531714_error_006() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -258,33 +247,43 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
* should compile - test for adding additional nesting in variables
* dev note: ref consumeToken().case Switch
*/
- public void testBug531714_error_007() {
- runConformTest(
- new String[] {
- "X.java",
- "public class X {\n"+
- " static int foo(int i) {\n"+
- " int tw = \n"+
- " switch (i) {\n"+
- " case 1 -> \n"+
- " {\n"+
- " int z = 100;\n"+
- " break z;\n"+
- " }\n"+
- " default -> {\n"+
- " break 12;\n"+
- " }\n"+
- " };\n"+
- " return tw;\n"+
- " }\n"+
- " public static void main(String[] args) {\n"+
- " System.out.print(foo(1));\n"+
- " }\n"+
- "}\n"
- },
- "100");
+ public void _testBug531714_error_007() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = \n"+
+ " switch (i) {\n"+
+ " case 1 -> \n"+
+ " {\n"+
+ " int z = 100;\n"+
+ " break z;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " break 12;\n"+
+ " }\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " default -> {\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " break 12;\n" +
+ " ^^\n" +
+ "Syntax error on token \"12\", delete this token\n" +
+ "----------\n");
}
- public void testBug531714_008() {
+ public void _testBug531714_008() {
Map<String, String> disablePreviewOptions = getCompilerOptions();
disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
String[] testFiles = new String[] {
@@ -328,7 +327,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"4. 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" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
this.runNegativeTest(
@@ -338,8 +337,8 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
disablePreviewOptions);
}
- public void testBug543667_001() {
- runConformTest(
+ public void _testBug543667_001() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -355,9 +354,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
},
- "hello");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> System.out.println(\"DEFAULT\");\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug531714_009() {
+ public void _testBug531714_009() {
Map<String, String> disablePreviewOptions = getCompilerOptions();
disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
String[] testFiles = new String[] {
@@ -392,7 +396,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"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" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -401,7 +405,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
disablePreviewOptions);
}
- public void testBug531714_010() {
+ public void _testBug531714_010() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.ERROR);
@@ -425,7 +429,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"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" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" default -> 3;\n" +
@@ -439,7 +443,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
options);
}
- public void testBug531714_011() {
+ public void _testBug531714_011() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
@@ -463,12 +467,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" default -> 3;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default -> 3;\n" +
" ^\n" +
"Invalid expression as statement\n" +
"----------\n";
this.runNegativeTest(
testFiles,
- expectedProblemLog);
+ expectedProblemLog,
+ null,
+ true,
+ getCompilerOptions());
}
public void testBug531714_012() {
Map<String, String> options = getCompilerOptions();
@@ -494,15 +506,10 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String expectedProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 4)\n" +
- " default -> 3;\n" +
- " ^^^^^^^\n" +
- "The preview feature Case Labels with \'->\' is only available with source level 12 and above\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 4)\n" +
- " default -> 3;\n" +
- " ^\n" +
- "Invalid expression as statement\n" +
+ "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" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -514,7 +521,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
options.put(CompilerOptions.OPTION_Source, release);
}
}
- public void testBug531714_013() {
+ public void _testBug531714_013() {
String[] testFiles = new String[] {
"X.java",
"public class X {\n" +
@@ -540,10 +547,10 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String expectedProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 8)\n" +
- " default :v = 2;\n" +
- " ^^^^^\n" +
- "A switch labeled block in a switch expression should not complete normally\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " break 0;\n" +
+ " ^\n" +
+ "Syntax error on token \"0\", delete this token\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -552,7 +559,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
getCompilerOptions());
}
- public void testBug531714_014() {
+ public void _testBug531714_014() {
// switch expression is not a Primary
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
@@ -572,16 +579,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
};
runner.expectedCompilerLog =
"----------\n" +
- "1. ERROR in X.java (at line 6)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> null;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
" }.toLowerCase());\n" +
" ^\n" +
"Syntax error on token \".\", , expected\n" +
"----------\n";
- runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("12");
runner.runNegativeTest();
}
- public void testBug543673_001() {
- runConformTest(
+ public void _testBug543673_001() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -603,12 +614,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
"}\n"
},
- "6");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> 10;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
/*
* A simple multi constant case statement, compiled and run as expected
*/
- public void testBug543240_1() {
+ public void _testBug543240_1() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -631,16 +647,24 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"enum Day { SATURDAY, SUNDAY, MONDAY;}",
};
- String expectedOutput =
- "SUNDAY";
- this.runConformTest(
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
- expectedOutput);
+ expectedProblemLog,
+ null,
+ true,
+ options);
}
/*
* A simple multi constant case statement, compiler reports missing enum constants
*/
- public void testBug543240_1a() {
+ public void _testBug543240_1a() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -668,16 +692,24 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" switch (day) {\n" +
" ^^^\n" +
"The enum constant TUESDAY needs a corresponding case label in this enum switch on Day\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
options);
}
/*
* A simple multi constant case statement with duplicate enums
*/
- public void testBug543240_2() {
+ public void _testBug543240_2() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -702,16 +734,21 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
String expectedProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 4)\n" +
- " case SATURDAY, SUNDAY: \n" +
- " ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Duplicate case\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 7)\n" +
- " case SUNDAY : System.out.println(Day.SUNDAY);\n" +
- " ^^^^^^^^^^^\n" +
- "Duplicate case\n" +
- "----------\n";
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case SUNDAY : System.out.println(Day.SUNDAY);\n" +
+ " ^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n";
this.runNegativeTest(
testFiles,
expectedProblemLog,
@@ -722,7 +759,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
/*
* A simple multi constant case statement with duplicate enums
*/
- public void testBug543240_2a() {
+ public void _testBug543240_2a() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -752,15 +789,25 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" case SATURDAY, SUNDAY: \n" +
- " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
"----------\n" +
- "3. ERROR in X.java (at line 7)\n" +
+ "4. ERROR in X.java (at line 7)\n" +
+ " case SUNDAY, SATURDAY : \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 7)\n" +
" case SUNDAY, SATURDAY : \n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
"----------\n" +
- "4. ERROR in X.java (at line 7)\n" +
+ "6. ERROR in X.java (at line 7)\n" +
" case SUNDAY, SATURDAY : \n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
@@ -775,7 +822,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
/*
*
*/
- public void testBug543240_3() {
+ public void _testBug543240_3() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -804,13 +851,21 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" switch (day) {\n" +
" ^^^\n" +
"The enum constant MONDAY needs a corresponding case label in this enum switch on Day\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
+ new String[] {"--enable-preview"},
options);
}
- public void testBug543240_4() {
+ public void _testBug543240_4() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -836,18 +891,23 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
};
String expectedProblemLog =
- "SATURDAY\n" +
- "0\n" +
- "SUNDAY";
- this.runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Simple switch case with string literals
*/
- public void testBug543240_5() {
+ public void _testBug543240_5() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -886,7 +946,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
options,
new String[] {"--enable-preview"});
}
- public void testBug543240_6() {
+ public void _testBug543240_6() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -914,20 +974,24 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}",
};
String expectedProblemLog =
- "A/B\n" +
- "A/B\n" +
- "C\n" +
- "NA";
- this.runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " case \"a\", \"b\":\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Switch with multi constant case statements with string literals
* two string literals with same hashcode
*/
- public void testBug543240_7() {
+ public void _testBug543240_7() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -955,19 +1019,23 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}",
};
String expectedProblemLog =
- "A\n" +
- "B\n" +
- "A\n" +
- "NA";
- this.runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " case \"FB\", \"c\":\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Switch with multi constant case statements with integer constants
*/
- public void testBug543240_8() {
+ public void _testBug543240_8() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -996,20 +1064,28 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}",
};
String expectedProblemLog =
- "Odd\n" +
- "Even\n" +
- "Odd\n" +
- "Even\n" +
- "Out of range";
- this.runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 14)\n" +
+ " case 2, 4: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Switch multi-constant with mixed constant types, reported
*/
- public void testBug543240_9() {
+ public void _testBug543240_9() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1034,7 +1110,12 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
};
String expectedProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 9)\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
" case \"2\": \n" +
" ^^^\n" +
"Type mismatch: cannot convert from String to int\n" +
@@ -1049,7 +1130,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
/*
* Switch multi-constant without break statement, reported
*/
- public void testBug543240_10() {
+ public void _testBug543240_10() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1074,20 +1155,27 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
};
String expectedProblemLog =
"----------\n" +
- "1. WARNING in X.java (at line 8)\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
" case 2, 4: \n" +
" ^^^^^^^^^\n" +
- "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Switch multi-constant without break statement, reported
*/
- public void testBug543240_11() {
+ public void _testBug543240_11() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1113,16 +1201,28 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" switch (i) {\n" +
" ^\n" +
"The switch statement should have a default case\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " case 2, 4: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(
+ this.runNegativeTest(
testFiles,
expectedProblemLog,
+ null,
+ true,
options);
}
/*
* Switch multi-constant with duplicate int constants
*/
- public void testBug543240_12() {
+ public void _testBug543240_12() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1146,9 +1246,19 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"1. ERROR in X.java (at line 6)\n" +
" case 1, 3: \n" +
" ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
"Duplicate case\n" +
"----------\n" +
- "2. ERROR in X.java (at line 8)\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " case 3, 4: \n" +
+ " ^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
" case 3, 4: \n" +
" ^^^^^^^^^\n" +
"Duplicate case\n" +
@@ -1163,7 +1273,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
/*
* Switch multi-constant with duplicate String literals
*/
- public void testBug543240_13() {
+ public void _testBug543240_13() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1187,9 +1297,19 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"1. ERROR in X.java (at line 6)\n" +
" case \"a\", \"b\": \n" +
" ^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case \"a\", \"b\": \n" +
+ " ^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
"----------\n" +
- "2. ERROR in X.java (at line 8)\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " case \"b\", \"c\": \n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
" case \"b\", \"c\": \n" +
" ^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
@@ -1204,7 +1324,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
/*
* Switch multi-constant with illegal qualified enum constant
*/
- public void testBug543240_14() {
+ public void _testBug543240_14() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1226,6 +1346,11 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
" case ONE, Num.TWO: \n" +
+ " ^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case ONE, Num.TWO: \n" +
" ^^^^^^^\n" +
"The qualified case label Num.TWO must be replaced with the unqualified enum constant TWO\n" +
"----------\n";
@@ -1236,7 +1361,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
options);
}
- public void testBug543240_15() {
+ public void _testBug543240_15() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1253,10 +1378,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
};
String expectedProblemLog =
"----------\n" +
- "1. ERROR in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
" default -> j;\n" +
- " ^\n" +
- "The local variable j may not have been initialized\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -1265,7 +1395,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
options);
}
- public void testBug543240_16() {
+ public void _testBug543240_16() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1283,12 +1413,27 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n",
};
- this.runConformTest(
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " default -> j;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n";
+ this.runNegativeTest(
testFiles,
- "",
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
options);
}
- public void testBug543795_01() {
+ public void _testBug543795_01() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -1322,13 +1467,18 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 10)\n" +
- " break;\n" +
- " ^^^^^^\n" +
- "Break of a switch expression should have a value\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " break 0;\n" +
+ " ^\n" +
+ "Syntax error on token \"0\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 12)\n" +
+ " default : break 10;\n" +
+ " ^^\n" +
+ "Syntax error on token \"10\", delete this token\n" +
"----------\n");
}
- public void testBug543691() {
+ public void _testBug543691() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1359,7 +1509,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
true,
options);
}
- public void testBug543799_1() {
+ public void _testBug543799_1() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1380,10 +1530,16 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
};
- String expectedOutput = "hello world";
- runConformTest(testFiles, expectedOutput, options);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> i == 3 ? null : \"\";\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n";
+ runNegativeTest(testFiles, expectedProblemLog, null, true, options);
}
- public void testBug543799_2() {
+ public void _testBug543799_2() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1404,10 +1560,21 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
};
- String expectedOutput = "hello world";
- runConformTest(testFiles, expectedOutput, options);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: break \"\";\n" +
+ " ^^\n" +
+ "Syntax error on token \"\"\"\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break i == 3 ? null : \"\";\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"break\", yield expected\n" +
+ "----------\n";
+ runNegativeTest(testFiles, expectedProblemLog, null, true, options);
}
- public void testBug543799_3() {
+ public void _testBug543799_3() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1435,10 +1602,16 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
};
- String expectedOutput = "NPE as expected";
- runConformTest(testFiles, expectedOutput, options);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " default -> b ? n1() : n2();\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n";
+ runNegativeTest(testFiles, expectedProblemLog, null, true, options);
}
- public void testBug543799_4() {
+ public void _testBug543799_4() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1467,10 +1640,16 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
};
- String expectedOutput = "NPE as expected";
- runConformTest(testFiles, expectedOutput, options);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " default -> this::n2;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n";
+ runNegativeTest(testFiles, expectedProblemLog, null, true, options);
}
- public void testBug543799_5() {
+ public void _testBug543799_5() {
// require resolving/inferring of poly-switch-expression during ASTNode.resolvePolyExpressionArguments()
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
@@ -1492,11 +1671,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
};
- String expectedOutput = "3";
- runConformTest(testFiles, expectedOutput, options);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> i == 3 ? 3 : 5.0d;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n";
+ runNegativeTest(testFiles, expectedProblemLog, null, true, options);
}
- public void testSwitchStatementWithBreakExpression() {
- runConformTest(
+ public void _testSwitchStatementWithBreakExpression() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1523,10 +1708,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "inside foo\n"
- + "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> throw new Exception();\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testSwitchStatementWithEnumValues() {
+ public void _testSwitchStatementWithEnumValues() {
runConformTest(
new String[] {
"X.java",
@@ -1550,9 +1739,11 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n" +
""
},
- "1");
+ "1",
+ null,
+ new String[] {"--enable-preview"});
}
- public void testBug543967_01() {
+ public void _testBug543967_01() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
String[] testFiles = new String[] {
@@ -1574,6 +1765,11 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" default -> 3; // should flag an error\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " default -> 3; // should flag an error\n" +
" ^\n" +
"Invalid expression as statement\n" +
"----------\n";
@@ -1585,8 +1781,8 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] { "--enable-preview"},
options);
}
- public void testBug544204() {
- runConformTest(
+ public void _testBug544204() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1603,10 +1799,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> i;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544204_2() {
- runConformTest(
+ public void _testBug544204_2() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1623,10 +1824,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "10");
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> 20L;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544223() {
- runConformTest(
+ public void _testBug544223() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1647,9 +1853,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> throw new Exception();\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544258_01() {
+ public void _testBug544258_01() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -1683,12 +1894,34 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY :\n" +
+ " today=1;\n" +
+ " break today;\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY :\n" +
+ " today=2;\n" +
+ " break today;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "A switch expression should have at least one result expression\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " today = switch (day) {\n" +
" ^^^\n" +
"A Switch expression should cover all possible values\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 5)\n" +
+ " case SATURDAY,SUNDAY :\n" +
+ " ^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY :\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n");
}
- public void testBug544253() {
- runConformTest(
+ public void _testBug544253() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1704,10 +1937,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "false");
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> true;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544254() {
- runConformTest(
+ public void _testBug544254() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1726,12 +1964,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "hello");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> 2;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544254_2() {
+ public void _testBug544254_2() {
Map<String, String> customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
- runConformTest(
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1750,12 +1993,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "hello");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> 2;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544254_3() {
+ public void _testBug544254_3() {
Map<String, String> customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
- runConformTest(
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1774,12 +2022,17 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "hello");
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " default -> 2;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544224_1() {
+ public void _testBug544224_1() {
Map<String, String> customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
- runConformTest(
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1795,11 +2048,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
},
- "",
- customOptions);
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> 2;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544298() {
- runConformTest(
+ public void _testBug544298() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1819,10 +2076,12 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "i:1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ "----------\n");
}
- public void testBug544298_2() {
- runConformTest(
+ public void _testBug544298_2() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1843,9 +2102,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "i:1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " default -> 0;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544428_01() {
+ public void _testBug544428_01() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
@@ -1870,6 +2134,11 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" case 0 -> x;\n" +
" ^\n" +
"x cannot be resolved to a variable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default -> 1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
"----------\n";
this.runNegativeTest(
testFiles,
@@ -1879,8 +2148,8 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] { "--enable-preview"},
options);
}
- public void testBug544523_01() {
- runConformTest(
+ public void _testBug544523_01() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1900,10 +2169,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " default -> 1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " default -> 1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544560_01() {
- runConformTest(
+ public void _testBug544560_01() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1922,10 +2201,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
},
- "1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> 1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " default -> 1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug544458() {
- runConformTest(
+ public void _testBug544458() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1941,10 +2230,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: i = 10; break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544458_2() {
- runConformTest(
+ public void _testBug544458_2() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1960,10 +2259,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: i++; break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544458_3() {
- runConformTest(
+ public void _testBug544458_3() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1979,10 +2288,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: i+= 10; break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544458_4() {
- runConformTest(
+ public void _testBug544458_4() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -1998,10 +2317,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: switch(i) {case 4: break;}; break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544458_5() {
- runConformTest(
+ public void _testBug544458_5() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2017,10 +2346,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 1: foo(5); break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544601_1() {
- runConformTest(
+ public void _testBug544601_1() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2046,10 +2385,20 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}\n"
},
- "1");
+ "----------\n" +
+ "1. ERROR in X.java (at line 13)\n" +
+ " break true;\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"true\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 14)\n" +
+ " default: break false;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"false\", delete this token\n" +
+ "----------\n");
}
- public void testBug544556() {
- runConformTest(
+ public void _testBug544556() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2070,10 +2419,30 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n" +
"}"
},
- "1");
- }
- public void testBug544702_01() {
- runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 0 -> { break 2; }\n" +
+ " ^\n" +
+ "Syntax error on token \"2\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " default -> { break 3; }\n" +
+ " ^\n" +
+ "Syntax error on token \"3\", delete this token\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " case 0 -> { break 0; }\n" +
+ " ^\n" +
+ "Syntax error on token \"0\", delete this token\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 10)\n" +
+ " default -> { break 1; }\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
+ "----------\n");
+ }
+ public void _testBug544702_01() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2092,10 +2461,15 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"\n" +
"}\n"
},
- "Success");
- }
- public void testBug545168_01() {
- runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " default -> k = -1;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
+ }
+ public void _testBug545168_01() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n" +
@@ -2118,10 +2492,25 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
"}\n"
},
- "9");
- }
- public void testBug545255_01() {
- runConformTest(
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case MONDAY, FRIDAY -> System.out.println(Day.SUNDAY);\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " default -> {}\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
+ }
+ public void _testBug545255_01() {
+ runNegativeTest(
new String[] {
"X.java",
"public class X {\n"+
@@ -2140,12 +2529,42 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n"+
"}\n"
},
- "0");
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 60, 600: break 6;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case 60, 600: break 6;\n" +
+ " ^\n" +
+ "Syntax error on token \"6\", delete this token\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 5)\n" +
+ " case 70: break 7;\n" +
+ " ^\n" +
+ "Syntax error on token \"7\", delete this token\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 6)\n" +
+ " case 80: break 8;\n" +
+ " ^\n" +
+ "Syntax error on token \"8\", delete this token\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 7)\n" +
+ " case 90, 900: break 9;\n" +
+ " ^\n" +
+ "Syntax error on token \"9\", delete this token\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 8)\n" +
+ " default: break 0;\n" +
+ " ^\n" +
+ "Syntax error on token \"0\", delete this token\n" +
+ "----------\n");
}
// see comment 12 in the bug
- public void testBug513766_01() {
- Runner runner = new Runner();
- runner.testFiles = new String[] {
+ public void _testBug513766_01() {
+ this.runNegativeTest(
+ new String[] {
"X.java",
"public class X {\n"+
" @SuppressWarnings(\"preview\")\n"+
@@ -2156,26 +2575,28 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" System.out.println(\"true, too\");\n"+
" }\n"+
" <T> T magic() { return null; }\n"+
- "}\n"};
- runner.expectedCompilerLog =
+ "}\n",
+ },
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" if (switch(i) { default -> magic(); })\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Type mismatch: cannot convert from Object to boolean\n" +
"----------\n" +
- "2. ERROR in X.java (at line 6)\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " if (switch(i) { default -> magic(); })\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" if (magic())\n" +
" ^^^^^^^\n" +
"Type mismatch: cannot convert from Object to boolean\n" +
- "----------\n";
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = JavacHasABug.JavacBug8179483_switchExpression;
- runner.runNegativeTest();
+ "----------\n");
}
- public void testBug545333() {
- Runner runner = new Runner();
- runner.testFiles = new String[] {
+ public void _testBug545333() {
+ runNegativeTest(
+ new String[] {
"X.java",
"public class X {\n"+
" @SuppressWarnings(\"preview\")\n"+
@@ -2196,8 +2617,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"class MyException extends Exception {\n"+
" private static final long serialVersionUID = 3461899582505930473L; \n"+
"}\n"
- };
- runner.expectedCompilerLog =
+ },
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" int v = switch (i) {\n" +
@@ -2205,12 +2625,14 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" };\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"A switch expression should have at least one result expression\n" +
- "----------\n";
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = JavacHasABug.JavacBug8226510_switchExpression;
- runner.runNegativeTest();
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " default -> throw new MyException();\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
}
- public void testBug545518() {
+ public void _testBug545518() {
if (this.complianceLevel < ClassFileConstants.JDK12)
return;
Map<String, String> options = getCompilerOptions();
@@ -2218,18 +2640,13 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
String message =
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR 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" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(new String[] {
+ this.runNegativeTest(new String[] {
"X.java",
"public class X {\n" +
" public static void main(String [] args) {\n" +
@@ -2241,9 +2658,12 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n"
},
message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
options);
}
- public void testBug545518a() {
+ public void _testBug545518a() {
if (this.complianceLevel < ClassFileConstants.JDK12)
return;
Map<String, String> options = getCompilerOptions();
@@ -2251,13 +2671,13 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
String message =
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
- " ^^^^^^^^^^^^\n" +
- "Dead code\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
- this.runWarningTest(new String[] {
+ this.runNegativeTest(new String[] {
"X.java",
"public class X {\n" +
" public static void main(String [] args) {\n" +
@@ -2269,9 +2689,12 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n"
},
message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
options);
}
- public void testBug545518b() {
+ public void _testBug545518b() {
if (this.complianceLevel < ClassFileConstants.JDK1_8)
return;
Map<String, String> options = getCompilerOptions();
@@ -2282,7 +2705,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"1. ERROR in X.java (at line 5)\n" +
" case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Multi constant case is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n";
this.runNegativeTest(new String[] {
@@ -2302,8 +2725,8 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] { "--enable-preview"},
options);
}
- public void testBug545715_01() {
- runConformTest(
+ public void _testBug545715_01() {
+ runNegativeTest(
new String[] {
"X.java",
"enum X {\n"+
@@ -2321,33 +2744,40 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
" }\n"+
"}\n"
},
- "5");
- }
- public void testBug545716_01() {
- Runner runner = new Runner();
- runner.testFiles = new String[] {
- "X.java",
- "enum X {\n"+
- " A, B;\n"+
- " \n"+
- " @SuppressWarnings(\"preview\")\n"+
- " public static void main(String[] args) {\n"+
- " X myEnum = X.A;\n"+
- " int o;\n"+
- " var f = switch(myEnum) {\n"+
- " case A -> o = 5;\n"+
- " case B -> o = 10;\n"+
- " };\n"+
- " System.out.println(o);\n"+
- " }\n"+
- "} \n"
- };
- runner.expectedOutputString = "5";
- runner.vmArguments = new String[] {"--enable-preview"};
- runner.javacTestOptions = JavacHasABug.JavacBug8221413_switchExpression;
- runner.runConformTest();
- }
- public void testBug545983_01() {
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " default -> o = 0;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
+ }
+ public void _testBug545916_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum X {\n"+
+ " A, B;\n"+
+ " \n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static void main(String[] args) {\n"+
+ " X myEnum = X.A;\n"+
+ " int o;\n"+
+ " var f = switch(myEnum) {\n"+
+ " case A -> o = 5;\n"+
+ " case B -> o = 10;\n"+
+ " };\n"+
+ " System.out.println(o);\n"+
+ " }\n"+
+ "} \n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " default -> o = 0;\n" +
+ " ^^^^^^^\n" +
+ "The preview feature Case Labels with \'->\' is only available with source level 13 and above\n" +
+ "----------\n");
+ }
+ public void _testBug545983_01() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -2373,13 +2803,13 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 11)\n" +
- " continue;\n" +
- " ^^^^^^^^^\n" +
- "'continue' or 'return' cannot be the last statement in a Switch expression case body\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " break 1;\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
"----------\n");
}
- public void testBug545983_02() {
+ public void _testBug545983_02() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -2405,13 +2835,13 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 11)\n" +
- " return 2;\n" +
- " ^^^^^^^^^\n" +
- "'continue' or 'return' cannot be the last statement in a Switch expression case body\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " break 1;\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
"----------\n");
}
- public void testBug547125_01() {
+ public void _testBug547125_01() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -2435,10 +2865,16 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"1. ERROR in X.java (at line 4)\n" +
" case SATURDAY, SUNDAY, SUNDAY:\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY, SUNDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
+ " ^^^^^^^\n" +
"----------\n");
}
- public void testBug547125_02() {
+ public void _testBug547125_02() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -2462,114 +2898,27 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
"1. ERROR in X.java (at line 4)\n" +
" case SATURDAY, SUNDAY, MONDAY:\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY, MONDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
"----------\n" +
- "2. ERROR in X.java (at line 6)\n" +
+ "3. ERROR in X.java (at line 6)\n" +
" case MONDAY, SUNDAY:\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
- "Duplicate case\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\n" +
"----------\n" +
- "3. ERROR in X.java (at line 6)\n" +
+ "4. ERROR in X.java (at line 6)\n" +
" case MONDAY, SUNDAY:\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"Duplicate case\n" +
- "----------\n");
- }
- public void testBug548476_01() {
- this.runNegativeTest(
- new String[] {
- "X.java",
- "class X {\n" +
- " I expr = () -> break;\n" +
- "}\n" +
- "\n" +
- "interface I {\n" +
- " void foo();\n" +
- "}",
- },
- "----------\n" +
- "1. ERROR in X.java (at line 2)\n" +
- " I expr = () -> break;\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", invalid LambdaBody\n" +
- "----------\n");
- }
- public void testBug548476_02() {
- this.runNegativeTest(
- new String[] {
- "X.java",
- "class X {\n" +
- " void break () {}\n" +
- "}",
- },
"----------\n" +
- "1. ERROR in X.java (at line 2)\n" +
- " void break () {}\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", Identifier expected\n" +
- "----------\n");
- }
- public void testBug548476_03() {
- this.runNegativeTest(
- new String[] {
- "X.java",
- "class X {\n" +
- "}\n" +
- "\n" +
- "class break{}\n"
- },
- "----------\n" +
- "1. ERROR in X.java (at line 4)\n" +
- " class break{}\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", Identifier expected\n" +
- "----------\n");
- }
- public void testBug548476_04() {
- this.runNegativeTest(
- new String[] {
- "module-info.java",
- "module break.me {\n" +
- "}\n"
- },
- "----------\n" +
- "1. ERROR in module-info.java (at line 1)\n" +
- " module break.me {\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", Identifier expected\n" +
- "----------\n");
- }
- public void testBug548476_05() {
- this.runNegativeTest(
- new String[] {
- "X.java",
- "class X {\n"+
- " public static void foo(int i) {\n"+
- " int v = switch (i) {\n"+
- " case 0 -> {\n"+
- " I k = () -> break;\n"+
- " }\n"+
- " default -> {\n"+
- " I k = () -> break;\n"+
- " break 0;\n"+
- " }\n"+
- " };\n"+
- " }\n"+
- "}\n"+
- "interface I {\n"+
- " void foo();\n"+
- "}\n"
- },
- "----------\n" +
- "1. ERROR in X.java (at line 5)\n" +
- " I k = () -> break;\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", invalid LambdaBody\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 8)\n" +
- " I k = () -> break;\n" +
- " ^^^^^\n" +
- "Syntax error on token \"break\", invalid LambdaBody\n" +
+ "5. ERROR in X.java (at line 6)\n" +
+ " case MONDAY, SUNDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
"----------\n");
}
}
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
new file mode 100644
index 0000000000..f0dd255882
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java
@@ -0,0 +1,3483 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.util.Map;
+
+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;
+
+import junit.framework.Test;
+
+public class SwitchExpressionsYieldTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] { "testBug550861_01" };
+ }
+
+ public static Class<?> testClass() {
+ return SwitchExpressionsYieldTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_13);
+ }
+ public SwitchExpressionsYieldTest(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_13); // FIXME
+ 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);
+ 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("13");
+ runner.runConformTest();
+ }
+ @Override
+ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) {
+ runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("13"));
+ }
+ 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("13") :
+ JavacTestOptions.forReleaseWithPreview("13", javacAdditionalTestOptions);
+ runner.runWarningTest();
+ }
+ public void testBug544073_000() {
+ runConformTest(
+ new String[] {
+ "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"
+ },
+ "1");
+ }
+ public void testBug544073_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " System.out.print(twice(3));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "3");
+ }
+ public void testBug544073_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int twice(int i) throws Exception {\n"+
+ " int tw = switch (i) {\n"+
+ " case 0 -> 0;\n"+
+ " case 1 -> { \n"+
+ " System.out.println(\"do_not_print\");\n"+
+ " yield 1;\n"+
+ " } \n"+
+ " case 3 -> throw new Exception();\n"+
+ " default -> throw new Exception();\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " try {\n"+
+ " try {\n"+
+ " System.out.print(twice(3));\n"+
+ " } catch (Exception e) {\n"+
+ " System.out.print(\"Got Exception - expected\");\n"+
+ " }\n"+
+ " } catch (Exception e) {\n"+
+ " System.out.print(\"Got Exception\");\n"+
+ " }\n"+
+ " }\n"+
+ "}\n"
+ },
+ "Got Exception - expected");
+ }
+ public void testBug544073_003() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " twice(1);\n" +
+ " }\n" +
+ " public static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " int tw = switch (i) {\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^\n" +
+ "A switch expression should have a non-empty switch block\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " int tw = switch (i) {\n" +
+ " ^\n" +
+ "A switch expression should have a default case\n" +
+ "----------\n");
+ }
+ public void testBug544073_004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " twice(1);\n" +
+ " }\n" +
+ " public static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> 0;\n" +
+ " case 1 -> { \n" +
+ " System.out.println(\"heel\");\n" +
+ " yield 1;\n" +
+ " } \n" +
+ " case \"hello\" -> throw new java.io.IOException(\"hello\");\n" +
+ " default -> throw new java.io.IOException(\"world\");\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " case \"hello\" -> throw new java.io.IOException(\"hello\");\n" +
+ " ^^^^^^^\n" +
+ "Type mismatch: cannot convert from String to int\n" +
+ "----------\n");
+ }
+ public void testBug544073_005() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " twice(1);\n" +
+ " }\n" +
+ " public static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> 0;\n" +
+ " case 1 -> { \n" +
+ " System.out.println(\"heel\");\n" +
+ " yield 1;\n" +
+ " } \n" +
+ " case 2 -> 2;\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " int tw = switch (i) {\n" +
+ " ^\n" +
+ "A switch expression should have a default case\n" +
+ "----------\n");
+ }
+ /**
+ * Add a test case for enum
+ * If the type of the selector expression is an enum type,
+ * then the set of all the case constants associated with the switch block
+ * must contain all the enum constants of that enum type
+ * Add a missing enum test case
+ */
+ public void _testBug544073_006() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " int x, y;\n" +
+ " I i = () -> {\n" +
+ " int z = 10;\n" +
+ " };\n" +
+ " i++;\n" +
+ " }\n" +
+ " public static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> 0;\n" +
+ " case 1 -> { \n" +
+ " System.out.println(\"heel\");\n" +
+ " yield 1;\n" +
+ " } \n" +
+ " // case 2 -> 2;\n" +
+ " case \"hello\" -> throw new IOException(\"hello\");\n" +
+ " };\n" +
+ " return tw;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " int tw = switch (i) {\n" +
+ " ^^^^^\n" +
+ " The switch expression should have a default case\n" +
+ "----------\n");
+ }
+ /*
+ * should compile - test for adding additional nesting in variables
+ * dev note: ref consumeToken().case Switch
+ */
+ public void testBug544073_007() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = \n"+
+ " switch (i) {\n"+
+ " case 1 -> \n"+
+ " {\n"+
+ " int z = 100;\n"+
+ " yield z;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " yield 12;\n"+
+ " }\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n"
+ },
+ "100");
+ }
+ public void testBug544073_008() {
+ Map<String, String> disablePreviewOptions = getCompilerOptions();
+ disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " return tw;\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" +
+ " int tw = switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\n" +
+ " default -> 3;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Switch Expressions is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case 0 -> i * 0;\n" +
+ " ^^^^^^\n" +
+ "Case Labels with '->' is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n" +
+ "3. 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" +
+ "4. 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";
+
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ disablePreviewOptions);
+ }
+ public void testBug544073_009() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1 -> System.out.println(\"hello\");\n" +
+ " default -> System.out.println(\"DEFAULT\");\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(1);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "hello");
+ }
+ public void testBug544073_010() {
+ Map<String, String> disablePreviewOptions = getCompilerOptions();
+ disablePreviewOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) {\n" +
+ " switch (i) {\n" +
+ " case 0 -> i * 0;\n" +
+ " case 1 -> 2;\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" +
+ " case 0 -> i * 0;\n" +
+ " ^^^^^^\n" +
+ "Case Labels with \'->\' is a preview feature and disabled by default. Use --enable-preview to enable\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" +
+ "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";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ disablePreviewOptions);
+ }
+ public void testBug544073_011() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.ERROR);
+ 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" +
+ "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";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug544073_012() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\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 5)\n" +
+ " default -> 3;\n" +
+ " ^\n" +
+ "Invalid expression as statement\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ public void testBug544073_013() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String release = options.get(CompilerOptions.OPTION_Release);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11);
+ try {
+ 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 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" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ } finally {
+ options.put(CompilerOptions.OPTION_Source, release);
+ }
+ }
+ public void testBug544073_014() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " int v;\n" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " yield 0;\n" +
+ " }\n" +
+ " default :v = 2;\n" +
+ " };\n" +
+ " return t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(3));\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " default :v = 2;\n" +
+ " ^^^^^\n" +
+ "A switch labeled block in a switch expression should not complete normally\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ public void testBug544073_015() {
+ // switch expression is not a Primary
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void test(int i) {\n" +
+ " System.out.println(switch (i) {\n" +
+ " case 1 -> \"one\";\n" +
+ " default -> null;\n" +
+ " }.toLowerCase());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().test(1);\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " }.toLowerCase());\n" +
+ " ^\n" +
+ "Syntax error on token \".\", , expected\n" +
+ "----------\n";
+ runner.runNegativeTest();
+ }
+ public void testBug544073_016() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(Day day) {\n" +
+ "\n" +
+ " var len= switch (day) {\n" +
+ " case SUNDAY-> 6;\n" +
+ " default -> 10;\n" +
+ " };\n" +
+ "\n" +
+ " return len;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(foo(Day.SUNDAY));\n" +
+ " }\n" +
+ "}\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}\n"
+ },
+ "6");
+ }
+ /*
+ * A simple multi constant case statement, compiled and run as expected
+ */
+ public void testBug544073_017() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\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" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}",
+ };
+
+ String expectedProblemLog =
+ "SUNDAY";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * A simple multi constant case statement, compiler reports missing enum constants
+ */
+ public void testBug544073_018() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\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" +
+ " }" +
+ "}\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY, TUESDAY;}",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 5)\n" +
+ " switch (day) {\n" +
+ " ^^^\n" +
+ "The enum constant TUESDAY needs a corresponding case label in this enum switch on Day\n" +
+ "----------\n";
+ this.runWarningTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * A simple multi constant case statement with duplicate enums
+ */
+ public void testBug544073_019() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " case SUNDAY : System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] args) {\n" +
+ " bar(Day.SATURDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " case SUNDAY : System.out.println(Day.SUNDAY);\n" +
+ " ^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * A simple multi constant case statement with duplicate enums
+ */
+ public void testBug544073_020() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " case SUNDAY, SATURDAY : \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ "}\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " switch (day) {\n" +
+ " ^^^\n" +
+ "The enum constant MONDAY needs a corresponding case label in this enum switch on Day\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " case SUNDAY, SATURDAY : \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 7)\n" +
+ " case SUNDAY, SATURDAY : \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ *
+ */
+ public void testBug544073_021() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " case TUESDAY : System.out.println(Day.SUNDAY);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] args) {\n" +
+ " bar(Day.SATURDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY, TUESDAY;}",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " switch (day) {\n" +
+ " ^^^\n" +
+ "The enum constant MONDAY needs a corresponding case label in this enum switch on Day\n" +
+ "----------\n";
+ this.runWarningTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ public void testBug544073_022() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ "public static void bar(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY: \n" +
+ " System.out.println(day);\n" +
+ " break;\n" +
+ " case MONDAY : System.out.println(0);\n" +
+ " break;\n" +
+ " }\n" +
+ " }" +
+ " public static void main(String[] args) {\n" +
+ " bar(Day.SATURDAY);\n" +
+ " bar(Day.MONDAY);\n" +
+ " bar(Day.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum Day { SATURDAY, SUNDAY, MONDAY;}",
+ };
+
+ String expectedProblemLog =
+ "SATURDAY\n" +
+ "0\n" +
+ "SUNDAY";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * Simple switch case with string literals
+ */
+ public void testBug544073_023() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(\"a\");\n" +
+ " bar(\"b\");\n" +
+ " bar(\"c\");\n" +
+ " bar(\"d\");\n" +
+ " }\n" +
+ " public static void bar(String s) {\n" +
+ " switch(s) {\n" +
+ " case \"a\":\n" +
+ " case \"b\":\n" +
+ " System.out.println(\"A/B\");\n" +
+ " break;\n" +
+ " case \"c\":\n" +
+ " System.out.println(\"C\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"NA\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "A/B\n" +
+ "A/B\n" +
+ "C\n" +
+ "NA";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ public void testBug544073_024() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(\"a\");\n" +
+ " bar(\"b\");\n" +
+ " bar(\"c\");\n" +
+ " bar(\"d\");\n" +
+ " }\n" +
+ " public static void bar(String s) {\n" +
+ " switch(s) {\n" +
+ " case \"a\", \"b\":\n" +
+ " System.out.println(\"A/B\");\n" +
+ " break;\n" +
+ " case \"c\":\n" +
+ " System.out.println(\"C\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"NA\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "A/B\n" +
+ "A/B\n" +
+ "C\n" +
+ "NA";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * Switch with multi constant case statements with string literals
+ * two string literals with same hashcode
+ */
+ public void testBug544073_025() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(\"FB\");\n" +
+ " bar(\"Ea\");\n" +
+ " bar(\"c\");\n" +
+ " bar(\"D\");\n" +
+ " }\n" +
+ " public static void bar(String s) {\n" +
+ " switch(s) {\n" +
+ " case \"FB\", \"c\":\n" +
+ " System.out.println(\"A\");\n" +
+ " break;\n" +
+ " case \"Ea\":\n" +
+ " System.out.println(\"B\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"NA\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "A\n" +
+ "B\n" +
+ "A\n" +
+ "NA";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * Switch with multi constant case statements with integer constants
+ */
+ public void testBug544073_026() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(1);\n" +
+ " bar(2);\n" +
+ " bar(3);\n" +
+ " bar(4);\n" +
+ " bar(5);\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " break;\n" +
+ " case 2, 4: \n" +
+ " System.out.println(\"Even\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"Out of range\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "Odd\n" +
+ "Even\n" +
+ "Odd\n" +
+ "Even\n" +
+ "Out of range";
+ this.runConformTest(
+ testFiles,
+ expectedProblemLog);
+ }
+ /*
+ * Switch multi-constant with mixed constant types, reported
+ */
+ public void testBug544073_027() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " break;\n" +
+ " case \"2\": \n" +
+ " System.out.println(\"Even\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"Out of range\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " case \"2\": \n" +
+ " ^^^\n" +
+ "Type mismatch: cannot convert from String to int\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ /*
+ * Switch multi-constant without break statement, reported
+ */
+ public void testBug544073_028() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.WARNING);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case 2, 4: \n" +
+ " System.out.println(\"Even\");\n" +
+ " break;\n" +
+ " default:\n" +
+ " System.out.println(\"Out of range\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 8)\n" +
+ " case 2, 4: \n" +
+ " ^^^^^^^^^\n" +
+ "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" +
+ "----------\n";
+ this.runWarningTest(
+ testFiles,
+ expectedProblemLog,
+ options,
+ "-Xlint:fallthrough");
+ }
+ /*
+ * Switch multi-constant without yield statement, reported
+ */
+ public void testBug544073_029() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case 2, 4: \n" +
+ " System.out.println(\"Even\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 5)\n" +
+ " switch (i) {\n" +
+ " ^\n" +
+ "The switch statement should have a default case\n" +
+ "----------\n";
+ this.runWarningTest(
+ testFiles,
+ expectedProblemLog,
+ options);
+ }
+ /*
+ * Switch multi-constant with duplicate int constants
+ */
+ public void testBug544073_030() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(int i) {\n" +
+ " switch (i) {\n" +
+ " case 1, 3: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case 3, 4: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1, 3: \n" +
+ " ^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " case 3, 4: \n" +
+ " ^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ /*
+ * Switch multi-constant with duplicate String literals
+ */
+ public void testBug544073_031() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(String s) {\n" +
+ " switch (s) {\n" +
+ " case \"a\", \"b\": \n" +
+ " System.out.println(\"Odd\");\n" +
+ " case \"b\", \"c\": \n" +
+ " System.out.println(\"Odd\");\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case \"a\", \"b\": \n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " case \"b\", \"c\": \n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ /*
+ * Switch multi-constant with illegal qualified enum constant
+ */
+ public void testBug544073_032() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public static void bar(Num s) {\n" +
+ " switch (s) {\n" +
+ " case ONE, Num.TWO: \n" +
+ " System.out.println(\"Odd\");\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "enum Num { ONE, TWO}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case ONE, Num.TWO: \n" +
+ " ^^^^^^^\n" +
+ "The qualified case label Num.TWO must be replaced with the unqualified enum constant TWO\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug544073_033() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void bar(int s) {\n" +
+ " int j = switch (s) {\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " default -> j;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " default -> j;\n" +
+ " ^\n" +
+ "The local variable j may not have been initialized\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug544073_034() {
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ " public void bar(int s) {\n" +
+ " int j = 0;" +
+ " j = switch (s) {\n" +
+ " case 1, 2, 3 -> (s+1);\n" +
+ " default -> j;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runConformTest(
+ testFiles,
+ "");
+ }
+ public void testBug544073_035() {
+ // TODO: Fix me
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " yield 0;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break;\n" +
+ " }\n" +
+ " default : yield 10;\n" +
+ " };\n" +
+ " return t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " try {\n" +
+ " System.out.println(foo(3));\n" +
+ " } catch (IOException e) {\n" +
+ " // TODO Auto-generated catch block\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " break;\n" +
+ " ^^^^^^\n" +
+ "break out of switch expression not allowed\n" +
+ "----------\n");
+ }
+ public void testBug544073_036() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void bar(int i) {\n" +
+ " i = switch (i+0) {\n" +
+ " default: System.out.println(0);\n" +
+ " }; " +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " i = switch (i+0) {\n" +
+ " default: System.out.println(0);\n" +
+ " }; }\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "A switch expression should have at least one result expression\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ }
+ public void testBug544073_037() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void test(int i) {\n" +
+ " need(switch (i) {\n" +
+ " case 1 -> \"\";\n" +
+ " default -> i == 3 ? null : \"\";\n" +
+ " }); \n" +
+ " }\n" +
+ " void need(String s) {\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().need(\"Hello World\");\n" +
+ " }\n" +
+ "}\n"
+ };
+ String expectedOutput = "hello world";
+ runConformTest(testFiles, expectedOutput, options);
+ }
+ public void testBug544073_038() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void test(int i) {\n" +
+ " need(switch (i) {\n" +
+ " case 1: yield \"\";\n" +
+ " default: yield i == 3 ? null : \"\";\n" +
+ " }); \n" +
+ " }\n" +
+ " void need(String s) {\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().need(\"Hello World\");\n" +
+ " }\n" +
+ "}\n"
+ };
+ String expectedOutput = "hello world";
+ runConformTest(testFiles, expectedOutput, options);
+ }
+ public void testBug544073_039() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "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(M m) { return m; }\n" +
+ " void test(int i, boolean b) {\n" +
+ " m(switch (i) {\n" +
+ " case 1 -> n1();\n" +
+ " default -> b ? n1() : 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"
+ };
+ String expectedOutput = "NPE as expected";
+ runConformTest(testFiles, expectedOutput, options);
+ }
+ public void testBug544073_040() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "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"
+ };
+ String expectedOutput = "NPE as expected";
+ runConformTest(testFiles, expectedOutput, options);
+ }
+ public void testBug544073_041() {
+ // require resolving/inferring of poly-switch-expression during ASTNode.resolvePolyExpressionArguments()
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void test(int i) {\n" +
+ " need(switch (i) {\n" +
+ " case 1 -> 1.0f;\n" +
+ " default -> i == 3 ? 3 : 5.0d;\n" +
+ " }); \n" +
+ " }\n" +
+ " <N extends Number> void need(N s) {\n" +
+ " System.out.println(s.toString());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().need(3);\n" +
+ " }\n" +
+ "}\n"
+ };
+ String expectedOutput = "3";
+ runConformTest(testFiles, expectedOutput, options);
+ }
+ public void testBug544073_042() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int twice(int i) throws Exception {\n" +
+ " switch (i) {\n" +
+ " case 0 -> System.out.println(\"hellow\");\n" +
+ " case 1 -> foo();\n" +
+ " default -> throw new Exception();\n" +
+ " };\n" +
+ " return 0;\n" +
+ " }\n" +
+ "\n" +
+ " static int foo() {\n" +
+ " System.out.println(\"inside foo\");\n" +
+ " return 1;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " try {\n" +
+ " System.out.print(twice(1));\n" +
+ " } catch (Exception e) {\n" +
+ " System.out.print(\"Got Exception\");\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "inside foo\n"
+ + "0");
+ }
+ public void testBug544073_043() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum SomeDays {\n" +
+ " Mon, Wed, Fri\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " int testEnum(boolean b) {\n" +
+ " SomeDays day = b ? SomeDays.Mon : null;\n" +
+ " return switch(day) {\n" +
+ " case Mon -> 1;\n" +
+ " case Wed -> 2;\n" +
+ " case Fri -> 3;\n" +
+ " };\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().testEnum(true));\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ },
+ "1");
+ }
+ public void testBug544073_044() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " static int foo(int i) {\n" +
+ " switch (i) {\n" +
+ " default -> 3; // should flag an error\n" +
+ " \n" +
+ " };\n" +
+ " return 0;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " foo(1);\n" +
+ " }\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " default -> 3; // should flag an error\n" +
+ " ^\n" +
+ "Invalid expression as statement\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug544073_045() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(int i) {\n" +
+ " int j = switch (i) {\n" +
+ " case 1 -> i;\n" +
+ " default -> i;\n" +
+ " };\n" +
+ " System.out.println(j);\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo(1);\n" +
+ " }\n" +
+ "}"
+ },
+ "1");
+ }
+ public void testBug544073_046() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(int i) {\n" +
+ " long j = switch (i) {\n" +
+ " case 1 -> 10L;\n" +
+ " default -> 20L;\n" +
+ " };\n" +
+ " System.out.println(j);\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo(1);\n" +
+ " }\n" +
+ "}"
+ },
+ "10");
+ }
+ public void testBug544073_047() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(String s) throws Exception {\n" +
+ " int i = switch (s) {\n" +
+ " case \"hello\" -> 1;\n" +
+ " default -> throw new Exception();\n" +
+ " };\n" +
+ " return i;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] argv) {\n" +
+ " try {\n" +
+ " System.out.print(new X().foo(\"hello\"));\n" +
+ " } catch (Exception e) {\n" +
+ " //\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "1");
+ }
+ public void testBug544073_048() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Day day) {\n" +
+ " var today = 1;\n" +
+ " today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY :\n" +
+ " today=1;\n" +
+ " yield today;\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY :\n" +
+ " today=2;\n" +
+ " yield today;\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(Day.FRIDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " SUNDAY,\n" +
+ " MONDAY,\n" +
+ " TUESDAY,\n" +
+ " WEDNESDAY,\n" +
+ " THURSDAY,\n" +
+ " FRIDAY,\n" +
+ " SATURDAY\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " today = switch (day) {\n" +
+ " ^^^\n" +
+ "A Switch expression should cover all possible values\n" +
+ "----------\n");
+ }
+ public void testBug544073_049() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(int i ) {\n" +
+ " boolean b = switch (i) {\n" +
+ " case 0 -> i == 1;\n" +
+ " default -> true;\n" +
+ " };\n" +
+ " System.out.println( b ? \" true\" : \"false\");\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " new X().foo(0);\n" +
+ " }\n" +
+ "}"
+ },
+ "false");
+ }
+ public void testBug544073_050() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(String s) {\n" +
+ " try {\n" +
+ " int i = switch (s) {\n" +
+ " case \"hello\" -> 0;\n" +
+ " default -> 2;\n" +
+ " };\n" +
+ " } finally {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(\"hello\");\n" +
+ " }\n" +
+ "}"
+ },
+ "hello");
+ }
+ public void testBug544073_051() {
+ Map<String, String> customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(String s) {\n" +
+ " try {\n" +
+ " int i = switch (s) {\n" +
+ " case \"hello\" -> 0;\n" +
+ " default -> 2;\n" +
+ " };\n" +
+ " } finally {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(\"hello\");\n" +
+ " }\n" +
+ "}"
+ },
+ "hello");
+ }
+ public void testBug544073_052() {
+ Map<String, String> customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(String s) {\n" +
+ " try {\n" +
+ " long l = switch (s) {\n" +
+ " case \"hello\" -> 0;\n" +
+ " default -> 2;\n" +
+ " };\n" +
+ " } finally {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(\"hello\");\n" +
+ " }\n" +
+ "}"
+ },
+ "hello");
+ }
+ public void testBug544073_053() {
+ Map<String, String> customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " int j = (switch (i) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> 2;\n" +
+ " });\n" +
+ " return j;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " new X().foo(1);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ customOptions);
+ }
+ public void testBug544073_054() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " enum MyEnum {\n" +
+ " FIRST;\n" +
+ " }\n" +
+ "\n" +
+ " public void foo(MyEnum myEnum) {\n" +
+ " int i = switch (myEnum) {\n" +
+ " case FIRST -> 1;\n" +
+ " };\n" +
+ " System.out.println( \"i:\" + i);\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(MyEnum.FIRST);\n" +
+ " }\n" +
+ "}"
+ },
+ "i:1");
+ }
+ public void testBug544073_055() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " enum MyEnum {\n" +
+ " FIRST;\n" +
+ " }\n" +
+ "\n" +
+ " public void foo(MyEnum myEnum) {\n" +
+ " int i = switch (myEnum) {\n" +
+ " case FIRST -> 1;\n" +
+ " default -> 0;\n" +
+ " };\n" +
+ " System.out.println( \"i:\" + i);\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String argv[]) {\n" +
+ " new X().foo(MyEnum.FIRST);\n" +
+ " }\n" +
+ "}"
+ },
+ "i:1");
+ }
+ public void testBug544073_056() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " var v = switch(i) {\n" +
+ " case 0 -> x;\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " return v;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case 0 -> x;\n" +
+ " ^\n" +
+ "x cannot be resolved to a variable\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug544073_057() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public int foo(int i) {\n" +
+ " int v = switch(i) {\n" +
+ " case 0 -> switch(i) {\n" +
+ " case 0 -> 0;\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " return v;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}"
+ },
+ "0");
+ }
+ public void testBug544073_058() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " int v = switch(switch(i) {\n" +
+ " default -> 1;\n" +
+ " }) {\n" +
+ " default -> 1;\n" +
+ " };\n" +
+ " return v;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1");
+ }
+ public void testBug544073_059() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: i = 10; yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(X.foo(0));\n" +
+ " }\n" +
+ "}"
+ },
+ "1");
+ }
+ public void testBug544073_060() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: i++; yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(X.foo(1));\n" +
+ " }\n" +
+ "}"
+ },
+ "0");
+ }
+ public void testBug544073_061() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: i+= 10; yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(X.foo(1));\n" +
+ " }\n" +
+ "}"
+ },
+ "0");
+ }
+ public void testBug544073_062() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: switch(i) {case 4: break;}; yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(X.foo(1));\n" +
+ " }\n" +
+ "}"
+ },
+ "0");
+ }
+ public void testBug544073_063() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: foo(5); yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(X.foo(1));\n" +
+ " }\n" +
+ "}"
+ },
+ "0");
+ }
+ public void testBug544073_064() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1:\n" +
+ " switch (i) {\n" +
+ " case 1 : i = 10;\n" +
+ " break;\n" +
+ " default :\n" +
+ " i = 2;\n" +
+ " break;\n" +
+ " }\n" +
+ " yield true;\n" +
+ " default: yield false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1");
+ }
+ public void testBug544073_065() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " int v =\n" +
+ " switch(switch(i) {\n" +
+ " case 0 -> { yield 2; }\n" +
+ " default -> { yield 3; }\n" +
+ " }) {\n" +
+ " case 0 -> { yield 0; }\n" +
+ " default -> { yield 1; }\n" +
+ " };\n" +
+ " return v == 1 ? v : 0;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}"
+ },
+ "1");
+ }
+ public void testBug544073_066() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public int foo(int i) {\n" +
+ " int k = 10;\n" +
+ " switch (i) {\n" +
+ " case 0 -> { k = 0;}\n" +
+ " default -> k = -1;\n" +
+ " }\n" +
+ " return k;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0) == 0 ? \"Success\" : \"Failure\");\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ },
+ "Success");
+ }
+ public void testBug544073_067() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case MONDAY, FRIDAY -> System.out.println(Day.SUNDAY);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " case WEDNESDAY -> System.out.println(9);\n" +
+ " default -> {}\n" +
+ " } \n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " X.foo(Day.WEDNESDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}\n"
+ },
+ "9");
+ }
+ public void testBug544073_068() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void foo (int i) {\n"+
+ " int v = switch (i) {\n"+
+ " case 60, 600: yield 6;\n"+
+ " case 70: yield 7;\n"+
+ " case 80: yield 8;\n"+
+ " case 90, 900: yield 9;\n"+
+ " default: yield 0;\n"+
+ " };\n"+
+ " System.out.println(v);\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo(10);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ // see comment 12 in the bug
+ public void testBug513766_01() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public void foo(int i) {\n"+
+ " if (switch(i) { default -> magic(); })\n"+
+ " System.out.println(\"true\");\n"+
+ " if (magic())\n"+
+ " System.out.println(\"true, too\");\n"+
+ " }\n"+
+ " <T> T magic() { return null; }\n"+
+ "}\n",
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " if (switch(i) { default -> magic(); })\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from Object to boolean\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " if (magic())\n" +
+ " ^^^^^^^\n" +
+ "Type mismatch: cannot convert from Object to boolean\n" +
+ "----------\n";
+ runner.vmArguments = new String[] {"--enable-preview"};
+ runner.javacTestOptions = JavacHasABug.JavacBug8179483_switchExpression;
+ runner.runNegativeTest();
+ }
+ public void testBug544073_070() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) throws MyException {\n"+
+ " int v = switch (i) {\n"+
+ " default -> throw new MyException();\n"+
+ " };\n"+
+ " return v;\n"+
+ " }\n"+
+ " public static void main(String argv[]) {\n"+
+ " try {\n"+
+ " System.out.println(X.foo(1));\n"+
+ " } catch (MyException e) {\n"+
+ " System.out.println(\"Exception thrown as expected\");\n"+
+ " }\n"+
+ " }\n"+
+ "}\n"+
+ "class MyException extends Exception {\n"+
+ " private static final long serialVersionUID = 3461899582505930473L; \n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " int v = switch (i) {\n" +
+ " default -> throw new MyException();\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "A switch expression should have at least one result expression\n" +
+ "----------\n");
+ }
+ public void testBug544073_071() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\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";
+
+ this.runWarningTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message,
+ options,
+ "-Xlint:preview");
+ }
+ public void testBug544073_072() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ String message =
+ "----------\n" +
+ "1. WARNING in X.java (at line 5)\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n";
+
+ this.runWarningTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message);
+ }
+ public void testBug544073_073() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Multi constant case is a preview feature and disabled by default. Use --enable-preview to enable\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " String arg = \"ABD\";\n" +
+ " switch(arg) {\n" +
+ " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug544073_074() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum X {\n"+
+ " A, B; \n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static void main(String[] args) {\n"+
+ " X myEnum = X.A;\n"+
+ " int o;\n"+
+ " switch(myEnum) {\n"+
+ " case A -> o = 5;\n"+
+ " case B -> o = 10;\n"+
+ " default -> o = 0;\n"+
+ " }\n"+
+ " System.out.println(o);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "5");
+ }
+ public void testBug544073_075() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum X {\n"+
+ " A, B;\n"+
+ " \n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static void main(String[] args) {\n"+
+ " X myEnum = X.A;\n"+
+ " int o;\n"+
+ " var f = switch(myEnum) {\n"+
+ " case A -> o = 5;\n"+
+ " case B -> o = 10;\n"+
+ " };\n"+
+ " System.out.println(o);\n"+
+ " }\n"+
+ "} \n"
+ },
+ "5");
+ }
+ public void testBug544073_076() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "\n"+
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo() {\n"+
+ " for (int i = 0; i < 1; ++i) {\n"+
+ " int k = switch (i) {\n"+
+ " case 0:\n"+
+ " yield 1;\n"+
+ " default:\n"+
+ " continue;\n"+
+ " };\n"+
+ " System.out.println(k);\n"+
+ " }\n"+
+ " return 1;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo();\n"+
+ " }\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " continue;\n" +
+ " ^^^^^^^^^\n" +
+ "'continue' or 'return' cannot be the last statement in a Switch expression case body\n" +
+ "----------\n");
+ }
+ public void testBug544073_077() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "\n"+
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo() {\n"+
+ " for (int i = 0; i < 1; ++i) {\n"+
+ " int k = switch (i) {\n"+
+ " case 0:\n"+
+ " yield 1;\n"+
+ " default:\n"+
+ " return 2;\n"+
+ " };\n"+
+ " System.out.println(k);\n"+
+ " }\n"+
+ " return 1;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo();\n"+
+ " }\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " return 2;\n" +
+ " ^^^^^^^^^\n" +
+ "'continue' or 'return' cannot be the last statement in a Switch expression case body\n" +
+ "----------\n");
+ }
+ public void testBug544073_078() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY, SUNDAY:\n" +
+ " System.out.println(\"Weekend\");\n" +
+ " case MONDAY:\n" +
+ " System.out.println(\"Weekday\");\n" +
+ " default: \n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY, SUNDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n");
+ }
+ public void testBug544073_079() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY, MONDAY:\n" +
+ " System.out.println(\"Weekend\");\n" +
+ " case MONDAY, SUNDAY:\n" +
+ " System.out.println(\"Weekday\");\n" +
+ " default: \n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " case SATURDAY, SUNDAY, MONDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " case MONDAY, SUNDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 6)\n" +
+ " case MONDAY, SUNDAY:\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Duplicate case\n" +
+ "----------\n");
+ }
+ public void testBug544073_80() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "\n"+
+ "public class X {\n"+
+ "\n"+
+ " public static int yield() {\n"+
+ " return 1;\n"+
+ " }\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int val) {\n"+
+ " return bar (switch (val) {\n"+
+ " case 1 : { yield val == 1 ? 2 : 3; }\n"+
+ " default : { yield 2; }\n"+
+ " });\n"+
+ " }\n"+
+ " public static int bar(int val) {\n"+
+ " return val;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(1));\n"+
+ " }\n"+
+ "}\n"
+ },
+ "2");
+ }
+ public void testBug544073_81() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int val) {\n"+
+ " int k = switch (val) {\n"+
+ " case 1 : { break 1; }\n"+
+ " default : { break 2; }\n"+
+ " };\n"+
+ " return k;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(1));\n"+
+ " }\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1 : { break 1; }\n" +
+ " ^\n" +
+ "Syntax error on token \"1\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " default : { break 2; }\n" +
+ " ^\n" +
+ "Syntax error on token \"2\", delete this token\n" +
+ "----------\n");
+ }
+ public void testBug547891_01() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void yield() {}\n"+
+ " public static void main(String[] args) {\n"+
+ " yield();\n"+
+ " X.yield();\n"+
+ " }\n"+
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " yield();\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n");
+ }
+ public void testBug547891_02() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void yield() {}\n"+
+ " public static void main(String[] args) {\n"+
+ " yield();\n"+
+ " }\n"+
+ " public static void bar() {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING in X.java (at line 4)\n" +
+ " yield();\n" +
+ " ^^^^^^^\n" +
+ "yield may be disallowed in future - qualify method calls to avoid this message\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_03() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield 1;\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " yield 1;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"yield\", AssignmentOperator expected after this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_04() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield 1;\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " yield 1;\n" +
+ " ^^^^^\n" +
+ "Syntax error on token \"yield\", AssignmentOperator expected after this token\n" +
+ "----------\n" +
+ "2. WARNING 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" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_05() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield y;\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " yield y;\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_06() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield y;\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING 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" +
+ "----------\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" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_07() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield y = null;\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " yield y = null;\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_08() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield y = null;\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING 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" +
+ "----------\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" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ } public void testBug547891_09() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_10() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n" +
+ "2. WARNING 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" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_11() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " new yield();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " new yield();\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_12() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " new yield();\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING 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" +
+ "----------\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" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_13() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield[] y;\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " yield[] y;\n" +
+ " ^^^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield is a restricted identifier and cannot be used as type name\n" +
+ "----------\n");
+ }
+ public void testBug547891_14() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
+ String[] testFiles = new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " yield[] y;\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"+
+ "class yield {\n" +
+ "}\n",
+ };
+ String expectedProblemLog =
+ "----------\n" +
+ "1. WARNING 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" +
+ "----------\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" +
+ " class yield {\n" +
+ " ^^^^^\n" +
+ "yield may be a restricted identifier in future and may be disallowed as a type name\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {""},
+ options);
+ }
+ public void testBug547891_15() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 1 -> yield();\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " case 3 -> {yield yield();}\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 10)\n" +
+ " default -> { yield yield();}\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) {\n"+
+ " int r = switch(i) {\n"+
+ " case 1 -> yield();\n"+
+ " case 2 -> X.yield();\n"+
+ " case 3 -> {yield yield();}\n"+
+ " case 4 -> {yield X.yield();}\n"+
+ " default -> { yield yield();}\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static int yield() {\n"+
+ " return 0;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}\n"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug547891_16() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " case 3 -> {yield yield();}\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " default -> { yield yield();}\n" +
+ " ^^^^^^^\n" +
+ "restricted identifier yield not allowed here - method calls need to be qualified\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n"+
+ "\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public int foo(int i) {\n"+
+ " X x = new X();\n"+
+ " int r = switch(i) {\n"+
+ " case 1 -> this.yield();\n"+
+ " case 2 -> x.new Y().yield();\n"+
+ " case 3 -> {yield yield();}\n"+
+ " case 4 -> {yield new X().yield() + x.new Y().yield();}\n"+
+ " default -> { yield yield();}\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public int yield() {\n"+
+ " return 0;\n"+
+ " }\n"+
+ " class Y {\n"+
+ " public int yield() {\n"+
+ " return 0;\n"+
+ " } \n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(new X().foo(0));\n"+
+ " }\n"+
+ "}\n"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug547891_17() {
+ runConformTest(
+ new String[] {
+ "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 - 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"+
+ "}"
+ },
+ "99");
+ }
+ public void testBug547891_18() {
+ runConformTest(
+ new String[] {
+ "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 - 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"+
+ "}"
+ },
+ "-1");
+ }
+ public void testBug547891_19() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int yield = 100;\n"+
+ "\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"+
+ "}"
+ },
+ "99");
+ }
+ public void testBug547891_20() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " static int yield = 100;\n"+
+ "\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"+
+ "}"
+ },
+ "-1");
+ }
+ public void testBug547891_21() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ String message =
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " default -> yield - 1;\n" +
+ " ^^^^^\n" +
+ "Cannot make a static reference to the non-static field yield\n" +
+ "----------\n";
+
+ this.runNegativeTest(new String[] {
+ "X.java",
+ "public class X {\n"+
+ " int yield = 100;\n"+
+ "\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"+
+ "}"
+ },
+ message,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug547891_22() {
+ runConformTest(
+ new String[] {
+ "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"
+ },
+ "256");
+ }
+ public void testBug547891_23() {
+ runConformTest(
+ new String[] {
+ "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"+
+ " int yield = 500 ;\n"+
+ " yield: while (yield == 500) {\n"+
+ " yield = 1024;\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"
+ },
+ "1024");
+ }
+ public void testBug547891_24() {
+ runConformTest(
+ new String[] {
+ "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 yield + 1;}\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}"
+ },
+ "101");
+ }
+ public void testBug547891_25() {
+ runConformTest(
+ new String[] {
+ "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 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"+
+ "}"
+ },
+ "10200");
+ }
+ public void testBug547891_26() {
+ runConformTest(
+ new String[] {
+ "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 + 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"+
+ "}"
+ },
+ "10200");
+ }
+ public void testBug547891_27() {
+ runConformTest(
+ new String[] {
+ "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 ->0 + yield + 10;\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}"
+ },
+ "110");
+ }
+ public void testBug547891_28() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) {\n"+
+ " int yield = 100;\n"+
+ " int r = switch(i) {\n"+
+ " case 0 : yield 100;\n"+
+ " case 1 : yield yield;\n"+
+ " default: yield 0;\n"+
+ " };\n"+
+ " return r;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}"
+ },
+ "100");
+ }
+ public void testBug547891_29() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static int foo(int i) {\n"+
+ " int yield = 100;\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"+
+ " System.out.println(X.foo(0));\n"+
+ " }\n"+
+ "}"
+ },
+ "300");
+ }
+ public void testBug550354_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings({ \"preview\" })\n"+
+ " public static int foo(int i) throws Exception {\n"+
+ " int v = switch (i) {\n"+
+ " default -> {if (i > 0) yield 1;\n"+
+ " else yield 2;}\n"+
+ " };\n"+
+ " return v;\n"+
+ " }\n"+
+ " public static void main(String argv[]) throws Exception {\n"+
+ " System.out.println(X.foo(1));\n"+
+ " }\n"+
+ "}"
+ },
+ "1");
+ }
+ public void testBug548418_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings({ \"preview\", \"unused\" })\n"+
+ " public static void main(String[] args) {\n"+
+ " int day =10;\n"+
+ " int i = switch (day) {\n"+
+ " default -> {\n"+
+ " for(int j = 0; j < 3; j++) {\n"+
+ " yield 99;\n"+
+ " }\n"+
+ " yield 0;\n"+
+ " }\n"+
+ " };\n"+
+ " System.out.println(i);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "99");
+ }
+ public void testBug550853_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings({ \"preview\" })\n"+
+ " public static int foo(int i) throws Exception {\n"+
+ " int v = switch (i) {\n"+
+ " default : {yield switch (i) {\n"+
+ " default -> { yield 0; } \n"+
+ " };\n"+
+ " }\n"+
+ " };\n"+
+ " return v;\n"+
+ " }\n"+
+ " public static void main(String argv[]) throws Exception {\n"+
+ " System.out.println(X.foo(1));\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug550861_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " @SuppressWarnings({ \"preview\" })\n"+
+ " public static void foo(int i) throws Exception {\n"+
+ " System.out.println(switch(0) {\n"+
+ " default -> {\n"+
+ " do yield 1; while(false);\n"+
+ " }\n"+
+ " });\n"+
+ " }\n"+
+ " public static void main(String argv[]) throws Exception {\n"+
+ " X.foo(1);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "1");
+ }
+ public void testBug551030a() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"nls\")\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " public static void main(String[] args) {\n" +
+ " int num = switch (day) {\n" +
+ " case MONDAY: \n" +
+ " // Nothing\n" +
+ " default:\n" +
+ " yield \"; \n" +
+ " }; \n" +
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " yield \"; \n" +
+ " ^^^^^^^\n" +
+ "String literal is not properly closed by a double-quote\n" +
+ "----------\n");
+ }
+ public void testBug551030b() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"nls\")\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " public static void main(String[] args) {\n" +
+ " int num = switch (day) {\n" +
+ " case MONDAY: \n" +
+ " // Nothing\n" +
+ " default:\n" +
+ " yield \"\"\"; \n" +
+ " }; \n" +
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " yield \"\"\"; \n" +
+ " ^^^^^^^\n" +
+ "String literal is not properly closed by a double-quote\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/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java
index 004768ede2..cfe6b0ddb0 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 @@ public void testBug545518() {
"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 12 and above\n" +
+ "The preview feature Multi constant case is only available with source level 13 and above\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 0fd2a6bf58..bfa912989a 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
@@ -184,6 +184,11 @@ public static Test suite() {
since_12.add(SwitchExpressionTest.class);
since_12.add(Unicode11Test.class);
+ // add 13 specific test here (check duplicates)
+ ArrayList since_13 = new ArrayList();
+ since_13.add(SwitchExpressionsYieldTest.class);
+ since_13.add(Unicode12_1Test.class);
+
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
all.addTest(new TestSuite(StandAloneASTParserTest.class));
@@ -295,6 +300,21 @@ public static Test suite() {
TestCase.resetForgottenFilters(tests_12);
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12), tests_12));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_13) != 0) {
+ ArrayList tests_13 = (ArrayList)standardTests.clone();
+ tests_13.addAll(since_1_4);
+ tests_13.addAll(since_1_5);
+ tests_13.addAll(since_1_6);
+ tests_13.addAll(since_1_7);
+ tests_13.addAll(since_1_8);
+ tests_13.addAll(since_9);
+ tests_13.addAll(since_10);
+ tests_13.addAll(since_11);
+ tests_13.addAll(since_12);
+ tests_13.addAll(since_13);
+ TestCase.resetForgottenFilters(tests_13);
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13), tests_13));
+ }
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/Unicode12_1Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java
new file mode 100644
index 0000000000..11f4a39819
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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.compiler.regression;
+
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+public class Unicode12_1Test extends AbstractRegressionTest {
+public Unicode12_1Test(String name) {
+ super(name);
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_13);
+}
+public void test1() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" +
+ "}",
+ },
+ "",
+ options);
+}
+public void test2() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" +
+ " ^^^^^^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+}
+public static Class<Unicode12_1Test> testClass() {
+ return Unicode12_1Test.class;
+}
+}
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 170bb63642..5aac8b39e0 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
@@ -32,7 +32,6 @@ 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.ExpressionStatement;
@@ -55,6 +54,7 @@ import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.YieldStatement;
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -64,7 +64,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
super(name);
}
- private static final int AST_JLS_LATEST = AST.JLS12;
+ private static final int AST_JLS_LATEST = AST.JLS13;
public ASTNode runConversion(
int astLevel,
@@ -1591,7 +1591,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
super.acceptAST(sourceFilePath, ast);
}
};
- ASTParser parser = ASTParser.newParser(AST.JLS11);
+ ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
@@ -1622,7 +1622,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
" for (var i = 0; i < 10; ++i) {}\n" +
" }\n" +
"}";
- ASTParser parser = ASTParser.newParser(AST.JLS11);
+ ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
parser.setSource(contents.toCharArray());
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
@@ -1758,6 +1758,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
SimpleName simpleName = (SimpleName) name;
assertFalse("A var", simpleName.isVar());
}
+ @Deprecated
public void testBug545383_01() throws JavaModelException {
String contents =
"class X {\n"+
@@ -1785,14 +1786,44 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
ASTNode node = parser.createAST(null);
assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
CompilationUnit cu = (CompilationUnit) node;
+ IProblem[] problems = cu.getProblems();
+ assertTrue(problems.length > 0);
+ assertTrue(problems[0].toString().contains("preview"));
+ }
+ public void testBug547900_01() throws JavaModelException {
+ String contents =
+ "class X {\n"+
+ " public static int foo(int i) {\n"+
+ " int result = switch (i) {\n"+
+ " case 1 -> {yield 5;}\n"+
+ " default -> 0;\n"+
+ " };\n"+
+ " return result;\n"+
+ " }\n"+
+ "}\n";
+
+ ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
+ parser.setSource(contents.toCharArray());
+ 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);
+ parser.setCompilerOptions(options);
+
+ ASTNode node = parser.createAST(null);
+ assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
+ CompilationUnit cu = (CompilationUnit) node;
TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0);
MethodDeclaration[] methods = typeDeclaration.getMethods();
MethodDeclaration methodDeclaration = methods[0];
VariableDeclarationStatement stmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0);
VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
SwitchExpression se = (SwitchExpression) fragment.getInitializer();
- BreakStatement breakStatement = (BreakStatement) ((Block)se.statements().get(1)).statements().get(0);
- assertNull("Unexpected Non null label", breakStatement.getLabel());
- assertNotNull("Expression null", breakStatement.getExpression());
+ YieldStatement yieldStatement = (YieldStatement) ((Block)se.statements().get(1)).statements().get(0);
+ assertNotNull("Expression null", yieldStatement.getExpression());
}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java
index 80eecdce87..433f8bf239 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.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
@@ -112,8 +112,10 @@ public String[] getCommandLine() {
long vmVersion = Util.getMajorMinorVMVersion();
if (vmVersion != -1) {
- if (vmVersion >= ClassFileConstants.JDK1_6) {
+ if (vmVersion < ClassFileConstants.JDK13) { // FailOverToOldVerifier deprecated from 13
commandLine.addElement("-XX:-FailOverToOldVerifier");
+ }
+ if (vmVersion >= ClassFileConstants.JDK1_6) {
commandLine.addElement("-Xverify:all");
}
if (vmVersion >= ClassFileConstants.JDK1_7) {
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 ace9a6a75a..e64a3878f8 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
@@ -44,6 +44,7 @@ public class AbstractCompilerTest extends TestCase {
public static final int F_10 = 0x80;
public static final int F_11 = 0x100;
public static final int F_12 = 0x200;
+ public static final int F_13 = 0x400;
public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));
private static final int UNINITIALIZED = -1;
@@ -55,6 +56,7 @@ public class AbstractCompilerTest extends TestCase {
protected static boolean isJRE9Plus = false; // Stop gap, so tests need not be run at 9, but some tests can be adjusted for JRE 9
protected static boolean isJRE11Plus = false;
protected static boolean isJRE12Plus = false;
+ protected static boolean isJRE13Plus = false;
protected static boolean reflectNestedClassUseDollar;
/**
@@ -102,6 +104,9 @@ public class AbstractCompilerTest extends TestCase {
if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
+ }
}
/**
@@ -147,6 +152,9 @@ public class AbstractCompilerTest extends TestCase {
if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
+ suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
+ }
return suite;
}
@@ -154,8 +162,9 @@ public class AbstractCompilerTest extends TestCase {
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);
- isJRE11Plus = isJRELevel(F_11);
- isJRE12Plus = isJRELevel(F_12);
+ isJRE13Plus = isJRELevel(F_13);
+ isJRE12Plus = isJRE13Plus || isJRELevel(F_12);
+ isJRE11Plus = isJRE12Plus || isJRELevel(F_11);
}
/**
@@ -306,6 +315,14 @@ public class AbstractCompilerTest extends TestCase {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
}
}
+ int level_13 = complianceLevels & AbstractCompilerTest.F_13;
+ if (level_13 != 0) {
+ if (level_13 < minimalCompliance) {
+ System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance 13!");
+ } else {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)));
+ }
+ }
return suite;
}
@@ -364,6 +381,9 @@ public class AbstractCompilerTest extends TestCase {
*/
public static long highestComplianceLevels() {
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
+ if ((complianceLevels & AbstractCompilerTest.F_13) != 0) {
+ return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13);
+ }
if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12);
}
@@ -420,7 +440,8 @@ public class AbstractCompilerTest extends TestCase {
public static int getPossibleComplianceLevels() {
if (possibleComplianceLevels == UNINITIALIZED) {
String specVersion = System.getProperty("java.specification.version");
- isJRE12Plus = CompilerOptions.VERSION_12.equals(specVersion);
+ isJRE13Plus = 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)
|| CompilerOptions.VERSION_10.equals(specVersion);
@@ -449,6 +470,8 @@ public class AbstractCompilerTest extends TestCase {
possibleComplianceLevels |= F_11;
} else if (CompilerOptions.VERSION_12.equals(compliance)) {
possibleComplianceLevels |= F_12;
+ } else if (CompilerOptions.VERSION_13.equals(compliance)) {
+ possibleComplianceLevels |= F_13;
} else {
System.out.println("Ignoring invalid compliance (" + compliance + ")");
System.out.print("Use one of ");
@@ -462,7 +485,8 @@ public class AbstractCompilerTest extends TestCase {
System.out.print(CompilerOptions.VERSION_9 + ", ");
System.out.print(CompilerOptions.VERSION_10 + ", ");
System.out.print(CompilerOptions.VERSION_11 + ", ");
- System.out.println(CompilerOptions.VERSION_12);
+ System.out.print(CompilerOptions.VERSION_12 + ", ");
+ System.out.println(CompilerOptions.VERSION_13);
}
}
if (possibleComplianceLevels == 0) {
@@ -512,6 +536,10 @@ public class AbstractCompilerTest extends TestCase {
if (canRun12) {
possibleComplianceLevels |= F_12;
}
+ boolean canRun13 = canRun12 && !CompilerOptions.VERSION_12.equals(specVersion);
+ if (canRun13) {
+ possibleComplianceLevels |= F_13;
+ }
} else if ("1.0".equals(specVersion)
|| CompilerOptions.VERSION_1_1.equals(specVersion)
|| CompilerOptions.VERSION_1_2.equals(specVersion)
@@ -534,6 +562,9 @@ public class AbstractCompilerTest extends TestCase {
possibleComplianceLevels |= F_11;
if (!CompilerOptions.VERSION_11.equals(specVersion)) {
possibleComplianceLevels |= F_12;
+ if (!CompilerOptions.VERSION_12.equals(specVersion)) {
+ possibleComplianceLevels |= F_13;
+ }
}
}
}
@@ -709,7 +740,7 @@ public class AbstractCompilerTest extends TestCase {
}
protected static String getVersionString(long compliance) {
- String version = "version 11 : 55.0";
+ String version = "version 13 : 57.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";
@@ -718,7 +749,7 @@ public class AbstractCompilerTest extends TestCase {
int major = Integer.parseInt(ver) + ClassFileConstants.MAJOR_VERSION_0;
return "version " + ver + " : " + major + ".0";
}
- if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11)) return version; // keep this stmt for search for next bump up
+ if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13)) return version; // keep this stmt for search for next bump up
return version;
}
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar b/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar
new file mode 100644
index 0000000000..0f621d1524
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin13.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip b/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip
new file mode 100644
index 0000000000..bf05b46301
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin13src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml
index 030204fa49..908e76d739 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -170,6 +170,37 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-13</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-13</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-13/configure -->
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13</tycho.surefire.argLine>
+ </properties>
+ </profile>
</profiles>
</project>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java
index eabf761ddc..ee41a3566d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java
@@ -15,7 +15,6 @@ package org.eclipse.jdt.core.tests;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.eclipse.jdt.core.tests.dom.ASTConverter12Test;
import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
@@ -35,12 +34,6 @@ public class RunAllJava12Tests extends TestCase {
};
}
- public static Class[] getConverterTestClasses() {
- return new Class[] {
- ASTConverter12Test.class,
- };
- }
-
public static Class[] getCompilerClasses() {
return new Class[] {
org.eclipse.jdt.core.tests.eval.TestAll.class,
@@ -53,8 +46,6 @@ public class RunAllJava12Tests extends TestCase {
Class[] testClasses = getAllTestClasses();
addTestsToSuite(ts, testClasses);
- testClasses = getConverterTestClasses();
- addTestsToSuite(ts, testClasses);
AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_11);
addTestsToSuite(ts, getCompilerClasses());
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
new file mode 100644
index 0000000000..bb3a1cf65c
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava13Tests.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.tests.compiler.parser.ComplianceDiagnoseTest;
+import org.eclipse.jdt.core.tests.compiler.regression.SwitchExpressionsYieldTest;
+import org.eclipse.jdt.core.tests.dom.ASTConverter13Test;
+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;
+import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunAllJava13Tests extends TestCase {
+
+ public RunAllJava13Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ JavaSearchBugs13Tests.class,
+ ComplianceDiagnoseTest.class,
+ SwitchExpressionsYieldTest.class,
+ org.eclipse.jdt.compiler.apt.tests.AllTests.class,
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+ ASTConverter13Test.class,
+ ASTRewritingTest.class,
+ };
+ }
+
+ public static Class[] getCompilerClasses() {
+ return new Class[] {
+ org.eclipse.jdt.core.tests.eval.TestAll.class,
+ org.eclipse.jdt.core.tests.compiler.regression.TestAll.class,
+ };
+ }
+
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunAllJava13Tests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ addTestsToSuite(ts, testClasses);
+ testClasses = getConverterTestClasses();
+ addTestsToSuite(ts, testClasses);
+
+ AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_13);
+ 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/RunOnlyJava12Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java
index 11bc2fa141..c1b0a66394 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java
@@ -14,10 +14,7 @@ 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.ASTConverter12Test;
import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
import junit.framework.Test;
@@ -36,19 +33,11 @@ public class RunOnlyJava12Tests extends TestCase {
};
}
- public static Class[] getConverterTestClasses() {
- return new Class[] {
- ASTConverter12Test.class
- };
- }
public static Test suite() {
TestSuite ts = new TestSuite(RunOnlyJava12Tests.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) {
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
new file mode 100644
index 0000000000..e8ef362a92
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava13Tests.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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.compiler.regression.SwitchExpressionsYieldTest;
+import org.eclipse.jdt.core.tests.dom.ASTConverter13Test;
+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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunOnlyJava13Tests extends TestCase {
+
+ public RunOnlyJava13Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ JavaSearchBugs13Tests.class,
+ SwitchExpressionsYieldTest.class,
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+ ASTConverter13Test.class,
+ ASTRewritingTest.class,
+ };
+ }
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunOnlyJava13Tests.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/ASTConverter10Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java
index e3d1479c3e..21285eaed7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java
@@ -34,9 +34,10 @@ public class ASTConverter10Test extends ConverterTestSetup {
// private static final String jcl9lib = "CONVERTER_JCL9_LIB";
+ @SuppressWarnings("deprecation")
public void setUpSuite() throws Exception {
super.setUpSuite();
- this.ast = AST.newAST(AST_INTERNAL_JLS11, true);
+ this.ast = AST.newAST(AST_INTERNAL_JLS10);
}
public ASTConverter10Test(String name) {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter11Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter11Test.java
index 1da181839d..8279e0b7e7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter11Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter11Test.java
@@ -24,6 +24,7 @@ public class ASTConverter11Test extends ConverterTestSetup {
ICompilationUnit workingCopy;
+ @SuppressWarnings("deprecation")
public void setUpSuite() throws Exception {
super.setUpSuite();
this.ast = AST.newAST(AST_INTERNAL_JLS11, true);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
index 9751f23fe5..867723c0b6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
@@ -7,47 +7,55 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *Contributors:
+ * 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.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 ASTConverter12Test extends ConverterTestSetup {
+public class ASTConverter13Test extends ConverterTestSetup {
ICompilationUnit workingCopy;
+ private static final String jclLib = "CONVERTER_JCL9_LIB";
public void setUpSuite() throws Exception {
super.setUpSuite();
- this.ast = AST.newAST(getAST12(), true);
+ this.ast = AST.newAST(getAST13(), false);
}
- public ASTConverter12Test(String name) {
+ public ASTConverter13Test(String name) {
super(name);
}
@@ -57,11 +65,11 @@ public class ASTConverter12Test extends ConverterTestSetup {
// TESTS_NAMES = new String[] {"test0001"};
}
public static Test suite() {
- return buildModelTestSuite(ASTConverter12Test.class);
+ return buildModelTestSuite(ASTConverter13Test.class);
}
- static int getAST12() {
- return AST.JLS12;
+ static int getAST13() {
+ return AST.JLS13;
}
protected void tearDown() throws Exception {
super.tearDown();
@@ -87,15 +95,15 @@ public class ASTConverter12Test extends ConverterTestSetup {
" case MONDAY -> throw new NullPointerException();\n" +
" case TUESDAY -> 1;\n" +
"\n" +
- " case WEDNESDAY -> {break 10;}\n" +
+ " case WEDNESDAY -> {yield 10;}\n" +
" default -> {\n" +
" int g = day.toString().length();\n" +
- " break g;\n" +
+ " yield g;\n" +
" }};\n" +
" System.out.println(k);\n" +
" }\n" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -154,7 +162,7 @@ public class ASTConverter12Test extends ConverterTestSetup {
" return today;\n" +
" }\n" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -199,16 +207,16 @@ public class ASTConverter12Test extends ConverterTestSetup {
" String today = \"\";\n" +
" today = switch (day) {\n" +
" case SATURDAY,SUNDAY:\n" +
- " break \"Weekend day\";\n" +
+ " yield \"Weekend day\";\n" +
" case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
- " break \"Week day\";\n" +
+ " yield \"Week day\";\n" +
" default:\n" +
- " break \"Any day\";\n" +
+ " yield \"Any day\";\n" +
" };\n" +
" return today;\n" +
" }\n" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -236,16 +244,16 @@ public class ASTConverter12Test extends ConverterTestSetup {
" String bb(Day day) throws Exception {\n" +
" String today = switch (day) {\n" +
" case SATURDAY,SUNDAY:\n" +
- " break \"Weekend day\";\n" +
+ " yield \"Weekend day\";\n" +
" case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
- " break \"Week day\";\n" +
+ " yield \"Week day\";\n" +
" default:\n" +
- " break \"Any day\";\n" +
+ " yield \"Any day\";\n" +
" };\n" +
" return today;\n" +
" }\n" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -271,7 +279,7 @@ public class ASTConverter12Test extends ConverterTestSetup {
assertEquals("incorrect name", "day", ((SimpleName) expression).getFullyQualifiedName());
List statements = ((SwitchExpression) initializer).statements();
assertEquals("incorrect no of statements", 6, statements.size());
- BreakStatement brStmt = (BreakStatement) statements.get(1);
+ YieldStatement brStmt = (YieldStatement) statements.get(1);
Expression expression2 = brStmt.getExpression();
assertNotNull("should not null", expression2);
assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
@@ -279,7 +287,7 @@ public class ASTConverter12Test extends ConverterTestSetup {
//default case:
SwitchCase caseStmt = (SwitchCase) statements.get(4);
assertTrue("not default", caseStmt.isDefault());
- brStmt = (BreakStatement) statements.get(5);
+ brStmt = (YieldStatement) statements.get(5);
expression2 = brStmt.getExpression();
assertNotNull("should not null", expression2);
assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
@@ -288,7 +296,8 @@ public class ASTConverter12Test extends ConverterTestSetup {
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void test0005() throws JavaModelException {
+ @Deprecated
+ public void _test0005() throws JavaModelException {
String contents =
"public class X {\n" +
" public String test001() {\n" +
@@ -301,7 +310,7 @@ public class ASTConverter12Test extends ConverterTestSetup {
" return ret;\n" +
" }" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -356,7 +365,7 @@ public class ASTConverter12Test extends ConverterTestSetup {
" return ret;\n" +
" }" +
"}" ;
- this.workingCopy = getWorkingCopy("/Converter12/src/X.java", true/*resolve*/);
+ this.workingCopy = getWorkingCopy("/Converter13/src/X.java", true/*resolve*/);
IJavaProject javaProject = this.workingCopy.getJavaProject();
String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
try {
@@ -388,4 +397,255 @@ public class ASTConverter12Test extends ConverterTestSetup {
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
+ // Moved over from ASTConverter9Test
+ 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");
+ return;
+ }
+ IJavaProject p = createJavaProject("Foo", new String[] {"src"}, new String[] {jclLib}, "bin", "13"); // FIXME jcl12?
+ p.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ p.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ 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_JLS13);
+ 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("/Converter13/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, 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("\"\"\""));
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ 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("/Converter13/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.DISABLED);
+ javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ try {
+ buildAST(
+ contents,
+ this.workingCopy);
+ } catch(UnsupportedOperationException e) {
+ fail("Should not throw UnsupportedOperationException");
+ } catch(AssertionFailedError e) {
+ e.printStackTrace();
+ return;
+ }
+ fail("Compilation should not succeed");
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ 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("/Converter13/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, 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());
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ public void test0010() throws JavaModelException {
+ String contents =
+ "public class test13 {\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("/Converter13/src/test13.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, 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()));
+ } 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/ASTConverter9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
index 74a2b6c99f..ae7f6c176b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
@@ -1417,94 +1417,10 @@ public class ASTConverter9Test extends ConverterTestSetup {
deleteProject("Foo");
}
}
- // TODO: should probably start a new test class
- public void testBug531714_015() throws CoreException {
- // saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
- if (!isJRE12) {
- System.err.println("Test "+getName()+" requires a JRE 12");
- return;
- }
- IJavaProject p = createJavaProject("Foo", new String[] {"src"}, new String[] {jcl9lib}, "bin", "12"); // FIXME jcl12?
- p.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- p.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- 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_JLS11);
- 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);
- }
- }
+ /**
+ * @deprecated
+ * @throws Exception
+ */
public void testBug542795() throws Exception {
IJavaProject p = createJavaProject("Foo", new String[] {"src"}, new String[] {jcl9lib}, "bin", "11");
try {
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 3ed0c55983..9158ad630e 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
@@ -372,7 +372,7 @@ public class ASTStructuralPropertyTest extends org.eclipse.jdt.core.tests.junit.
// oops - guess that's not valid
}
}
- assertEquals("Wrong last known type", 100, hi); // last known one
+ assertEquals("Wrong last known type", 102, hi); // last known one
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 79d7bddbfa..3aac660f89 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
@@ -27,6 +27,7 @@ import java.util.Map;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.*;
// testing
@@ -1308,14 +1309,35 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase
}
+ @SuppressWarnings("deprecation")
+ private static int getApiLevel(String s) {
+ if (s == null)
+ return AST.JLS12;
+ switch (s) {
+ case JavaCore.VERSION_1_2 : return AST.JLS2;
+ case JavaCore.VERSION_1_3: return AST.JLS3;
+ case JavaCore.VERSION_1_4: return AST.JLS4;
+ case JavaCore.VERSION_1_5: return AST.JLS4;
+ case JavaCore.VERSION_1_6: return AST.JLS4;
+ case JavaCore.VERSION_1_7: return AST.JLS4;
+ case JavaCore.VERSION_1_8: return AST.JLS8;
+ case JavaCore.VERSION_9: return AST.JLS9;
+ case JavaCore.VERSION_10: return AST.JLS10;
+ case JavaCore.VERSION_11: return AST.JLS11;
+ case JavaCore.VERSION_12: return AST.JLS12;
+ case JavaCore.VERSION_13: return AST.JLS13;
+ default: return AST.JLS2;
+ }
+ }
/** @deprecated using deprecated code */
public void testAST() {
assertSame(AST.JLS2, 2);
assertSame(JLS3_INTERNAL, 3);
- AST a0 = new AST(); // deprecated, but still 2.0
- assertTrue(a0.apiLevel() == AST.JLS2);
+ AST a0 = new AST(); // deprecated, now 3 from JavaCore.defaultOptions
+ int apiLevelCal = ASTTest.getApiLevel(JavaCore.getDefaultOptions().get(JavaCore.COMPILER_SOURCE));
+ assertTrue(a0.apiLevel() == apiLevelCal);
AST a1 = new AST(new HashMap()); // deprecated, but still 2.0
assertTrue(a1.apiLevel() == AST.JLS2);
AST a2 = AST.newAST(AST.JLS2, false);
@@ -8869,6 +8891,8 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase
ASTNode.PROVIDES_DIRECTIVE,
ASTNode.MODULE_MODIFIER,
ASTNode.SWITCH_EXPRESSION,
+ ASTNode.YIELD_STATEMENT,
+ ASTNode.TEXT_BLOCK
};
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 65102b4e48..034a46b084 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 @@ public class AbstractASTTests extends ModifyingResourceTests implements DefaultM
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_12)) {
+ 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;
} else if (jdkLevel >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11)) {
JLSLevel = AST_INTERNAL_JLS11;
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 47ab610d98..b5f936605e 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
@@ -105,7 +105,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
this.deleteProject("Converter9"); //$NON-NLS-1$
this.deleteProject("Converter10"); //$NON-NLS-1$
this.deleteProject("Converter11"); //$NON-NLS-1$
- this.deleteProject("Converter12"); //$NON-NLS-1$
+ this.deleteProject("Converter13"); //$NON-NLS-1$
PROJECT_SETUP = false;
} else {
TEST_SUITES.remove(getClass());
@@ -118,7 +118,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
this.deleteProject("Converter9"); //$NON-NLS-1$
this.deleteProject("Converter10"); //$NON-NLS-1$
this.deleteProject("Converter11"); //$NON-NLS-1$
- this.deleteProject("Converter12"); //$NON-NLS-1$
+ this.deleteProject("Converter13"); //$NON-NLS-1$
PROJECT_SETUP = false;
}
}
@@ -212,7 +212,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
setUpJavaProject("Converter9", "9"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter10", "10"); //$NON-NLS-1$ //$NON-NLS-2$
setUpJavaProject("Converter11", "11"); //$NON-NLS-1$ //$NON-NLS-2$
- setUpJavaProject("Converter12", "12"); //$NON-NLS-1$ //$NON-NLS-2$
+ setUpJavaProject("Converter13", "13"); //$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 f12cc67bab..cdaed01aea 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
@@ -52,7 +52,7 @@ public static Class[] getAllTestClasses() {
TypeAnnotationsConverterTest.class,
ASTConverter18Test.class,
ASTConverter9Test.class,
- ASTConverter12Test.class,
+ ASTConverter13Test.class,
};
}
public static Test suite() {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java
index 1da23d2ee1..9d6a88214f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.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
@@ -26,7 +26,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup {
public void setUpSuite() throws Exception {
super.setUpSuite();
- this.ast = AST.newAST(AST_INTERNAL_JLS11, false);
+ this.ast = AST.newAST(AST_INTERNAL_LATEST, false);
}
public TypeAnnotationsConverterTest(String name) {
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 71ad555547..320fe9a757 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
@@ -14850,7 +14850,7 @@ public void testBug541011g() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818a() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14861,7 @@ public void testBug543818a() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818b() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14872,7 @@ public void testBug543818b() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818c() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14883,7 @@ public void testBug543818c() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818d() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14895,7 @@ public void testBug543818d() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818e() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14906,7 @@ public void testBug543818e() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818f() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
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 +14917,7 @@ public void testBug543818f() throws JavaModelException {
* https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
*/
public void testBug543818g() throws JavaModelException {
- setComplianceLevel(CompilerOptions.VERSION_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
formatSource(input, getCompilationUnit("Formatter", "", "test543818", "G_out.java").getSource());
}
@@ -15230,7 +15230,7 @@ public void testBug421492d() throws JavaModelException {
* 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_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
this.formatterPrefs.blank_lines_between_statement_groups_in_switch = 2;
formatSourceInWorkspace("test390720", "in.java", "A_out.java");
}
@@ -15238,7 +15238,7 @@ public void testBug390720a() throws JavaModelException {
* 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_12);
+ setComplianceLevel(CompilerOptions.VERSION_13);
this.formatterPrefs.blank_lines_between_statement_groups_in_switch = ~0;
formatSourceInWorkspace("test390720", "in.java", "B_out.java");
}
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 43d9ab94c7..cf1f469db4 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
@@ -78,6 +78,7 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
protected static boolean isJRE10 = false;
protected static boolean isJRE11 = false;
protected static boolean isJRE12 = false;
+ protected static boolean isJRE13 = false;
protected static String DEFAULT_MODULES = null;
static {
String javaVersion = System.getProperty("java.version");
@@ -91,7 +92,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
}
}
long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion.length() > 3 ? javaVersion.substring(0, 3) : javaVersion);
- if (jdkLevel >= ClassFileConstants.getLatestJDKLevel()) {
+ if (jdkLevel >= ClassFileConstants.JDK13) {
+ isJRE13 = true;
+ }
+ if (jdkLevel >= ClassFileConstants.JDK12) {
isJRE12 = true;
}
if (jdkLevel >= ClassFileConstants.JDK11) {
@@ -144,14 +148,29 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
/**
* Internal synonym for constant AST.JSL12
* to alleviate deprecation warnings once AST.JLS12 is deprecated in future.
+ * @deprecated
*/
protected static final int AST_INTERNAL_JLS12 = AST.JLS12;
+
+ /**
+ * Internal synonym for constant AST.JSL13
+ * 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.JSL11
* to alleviate deprecation warnings once AST.JLS11 is deprecated in future.
+ * @deprecated
*/
protected static final int AST_INTERNAL_JLS11 = AST.JLS11;
+
+ /**
+ * Internal synonym for the latest AST level.
+ *
+ */
+ protected static final int AST_INTERNAL_LATEST = AST.JLS13;
+
public static class BasicProblemRequestor implements IProblemRequestor {
public void acceptProblem(IProblem problem) {}
public void beginReporting() {}
@@ -2082,6 +2101,12 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
javaProject.setOptions(options);
+ } else if ("13".equals(compliance)) {
+ Map options = new HashMap();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
+ javaProject.setOptions(options);
}
result[0] = javaProject;
}
@@ -3180,7 +3205,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
newJclSrcString = "JCL18_SRC"; // Use the same source
}
} else {
- if (compliance.equals("12")) {
+ if (compliance.equals("13")) {
+ newJclLibString = "JCL13_LIB";
+ newJclSrcString = "JCL13_SRC";
+ } else if (compliance.equals("12")) {
newJclLibString = "JCL12_LIB";
newJclSrcString = "JCL12_SRC";
} else if (compliance.equals("11")) {
@@ -3241,10 +3269,12 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
IPath jcl10Lib = new Path("JCL10_LIB");
IPath jcl11Lib = new Path("JCL11_LIB");
IPath jcl12Lib = new Path("JCL12_LIB");
+ IPath jcl13Lib = new Path("JCL13_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(jclFull);
+ || path.equals(jcl10Lib) || path.equals(jcl11Lib) || path.equals(jcl12Lib) || path.equals(jcl13Lib)
+ || path.equals(jclFull);
}
public void setUpJCLClasspathVariables(String compliance) throws JavaModelException, IOException {
setUpJCLClasspathVariables(compliance, false);
@@ -3315,6 +3345,14 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
new IPath[] {getExternalJCLPath("12"), getExternalJCLSourcePath("12"), getExternalJCLRootSourcePath()},
null);
}
+ } else if ("13".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("JCL13_LIB") == null) {
+ setupExternalJCL("jclMin13"); // No need for an explicit jclmin13, just use the same old one.
+ JavaCore.setClasspathVariables(
+ new String[] {"JCL13_LIB", "JCL13_SRC", "JCL_SRCROOT"},
+ new IPath[] {getExternalJCLPath("13"), getExternalJCLSourcePath("13"), getExternalJCLRootSourcePath()},
+ 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/AccessRestrictionsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java
index cd8839b09a..ec59a8e6fd 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java
@@ -1172,7 +1172,7 @@ public void testBug545766() throws CoreException {
createFolder("/P2/src/p2");
createFile("/P2/src/p2/Z.java", src);
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS12);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(p2);
parser.setSource((ITypeRoot)p2.findElement(new Path("p2/Z.java")));
parser.setResolveBindings(true);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
index 827e9f1bf6..296eb4f839 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.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
@@ -2656,7 +2656,7 @@ public void testBug495598_001() throws CoreException {
"public class X {}\n");
ICompilationUnit cuD = getCompilationUnit("/P/src/X.java");
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(this.testProject);
parser.setSource(cuD);
parser.setResolveBindings(true);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
index 03ba5f523d..5e0199ca5e 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.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
@@ -2684,7 +2684,7 @@ public void testBug351697() throws Exception {
proj.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
try {
- ASTParser parser= ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser= ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setSource(unit);
parser.setResolveBindings(true);
ASTNode node = parser.createAST(null);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs12Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs12Tests.java
deleted file mode 100644
index c1fced3a0f..0000000000
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs12Tests.java
+++ /dev/null
@@ -1,626 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019 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 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.IPackageFragment;
-import org.eclipse.jdt.core.IType;
-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;
-
-public class JavaSearchBugs12Tests 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 JavaSearchBugs12Tests(String name) {
- super(name);
- this.endChar = "";
-}
-public static Test suite() {
- return buildModelTestSuite(JavaSearchBugs12Tests.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", "12");
-}
-public void tearDownSuite() throws Exception {
- deleteProject("JavaSearchBugs");
- super.tearDownSuite();
-}
-protected void setUp () throws Exception {
- super.setUp();
- this.resultCollector = new TestCollector();
- this.resultCollector.showAccuracy(true);
-}
-
-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);
- }
-}
-public void testBug542559_002() 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 -> { break switch_expr_field; }\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\n" +
- "src/X.java int X.twice(int) [switch_expr_field] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-public void testBug542559_003() 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) throws Exception { \n" +
- " int tw = switch (i) { \n" +
- " case 0 -> { break switch_expr_field; } \n" +
- " case 4 -> throw new MyException(); \n" +
- " default -> 3; \n" +
- " }; \n" +
- " return tw; \n" +
- " } \n" +
- " public static void main(String[] args) {\n" +
- " try {\n" +
- " System.out.print(new X().twice(3));\n" +
- " } catch (Exception e) {\n" +
- " // TODO Auto-generated catch block\n" +
- " e.printStackTrace();\n" +
- " }\n" +
- " } \n" +
- "}\n" +
- "class MyException extends Exception {\n" +
- " private static final long serialVersionUID = 3461899582505930474L;\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);
- IType type = this.workingCopies[0].getType("MyException");
- search(type, REFERENCES);
- assertSearchResults(
- "src/X.java int X.twice(int) [MyException] 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.ENABLED);
- 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.ENABLED);
- 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.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);
- }
-}
-/*
- * 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);
- }
-}
-
-/*
- * 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 reference for class file reference in case and default blocks
- */
-public void testBug542559_009() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- " Integer abcd\n" +
- " public static int foo(int i) {\n" +
- " final int k;\n" +
- "\n" +
- " int it = switch (i) { \n" +
- " case 1 -> {\n" +
- " k = 1;\n" +
- " abcd.toString();\n" +
- " break k ;\n" +
- " }\n" +
- " case 2 -> {\n" +
- " abcd.toString();\n" +
- " break k ;\n" +
- " }\n" +
- " default -> {\n" +
- " k = 3;\n" +
- " abcd.toString();\n" +
- " break k;\n" +
- " }\n" +
- " };\n" +
- " return k;\n" +
- " }\n" +
- "\n" +
- " public boolean bar() {\n" +
- " return true;\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " System.out.println(foo(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("abcd", FIELD, REFERENCES);
- assertSearchResults(
- "src/X.java int X.foo(int) [abcd] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [abcd] EXACT_MATCH\n" +
- "src/X.java int X.foo(int) [abcd] EXACT_MATCH"
- );
- } finally {
- javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
- }
-}
-
-/*
- * java search reference for string constant in switch expression and switch statement
- */
-public void testBug542559_0010() throws CoreException {
- this.workingCopies = new ICompilationUnit[1];
- this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
- "public class X {\n" +
- " static final String MONDAY = \"MONDAY\";\n" +
- " static final String TUESDAY = \"TUESDAY\";\n" +
- " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
- " static final String THURSDAY = \"THURSDAY\";\n" +
- " static final String FRIDAY = \"FRIDAY\";\n" +
- " static final String SATURDAY = \"SATURDAY\";\n" +
- " static final String SUNDAY = \"SUNDAY\"; \n" +
- " @SuppressWarnings(\"preview\")\n" +
- " public static void main(String[] args) {\n" +
- " String day = \"MONDAY\";\n" +
- " switch (day) {\n" +
- " case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n" +
- " case TUESDAY -> System.out.println(7);\n" +
- " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
- " case WEDNESDAY -> System.out.println(9);\n" +
- " }\n" +
- " int k = switch (day) {\n" +
- " case SATURDAY -> throw new NullPointerException();\n" +
- " case TUESDAY -> 1;\n" +
- " case WEDNESDAY -> {break 10;}\n" +
- " default -> {\n" +
- " int g = day.h();\n" +
- " int result = f(g);\n" +
- " break result;\n" +
- " }};\n" +
- " }\n" +
- " static int f(int k) {\n" +
- " return k*k;\n" +
- " }\n" +
- "}\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.main(String[]) [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 a javatype reference from another java project if that is in switch expression
- */
-public void testBug542559_0011() throws CoreException {
- try {
-
- IJavaProject project1 = createJavaProject("JavaSearchBugs12", new String[] {"src"}, new String[] {"JCL12_LIB"}, "bin", "12");
- project1.open(null);
- createFolder("/JavaSearchBugs12/src/pack1");
- createFile("/JavaSearchBugs12/src/pack1/X11.java",
- "package pack1;\n" +
- "public class X11 { \n" +
- " static final String MONDAY = \"MONDAY\";\n" +
- " static final String TUESDAY = \"TUESDAY\";\n" +
- " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
- " static final String THURSDAY = \"THURSDAY\";\n" +
- " static final String FRIDAY = \"FRIDAY\";\n" +
- " static final String SATURDAY = \"SATURDAY\";\n" +
- " static final String SUNDAY = \"SUNDAY\"; \n" +
- " @SuppressWarnings(\"preview\")\n" +
- " public static void main(String[] args) {\n" +
- " String day = \"MONDAY\";\n" +
- " switch (day) {\n" +
- " case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n" +
- " case TUESDAY -> System.out.println(7);\n" +
- " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
- " case WEDNESDAY -> System.out.println(9);\n" +
- " }\n" +
- " int k = switch (day) {\n" +
- " case SATURDAY -> throw new NullPointerException();\n" +
- " case TUESDAY -> 1;\n" +
- " case WEDNESDAY -> {break 10;}\n" +
- " default -> {\n" +
- " pack2.X22.a2=99;\n" +
- " int result = f(g);\n" +
- " break result;\n" +
- " }};\n" +
- " }\n" +
- " static int f(int k) {\n" +
- " return k*k;\n" +
- " }\n" +
- "}\n");
-
- IJavaProject project2 = createJavaProject("second", new String[] {"src"},new String[] {"JCL12_LIB"}, "bin", "12");
- project2.open(null);
- createFolder("/second/src/pack2");
- createFile("/second/src/pack2/X22.java",
- "package pack2;\n" +
- "public class X22 {public static int a2=9;}\n");
- addClasspathEntry(project1, JavaCore.newProjectEntry(project2.getPath()));
- project1.close(); // sync
- project2.close();
- project2.open(null);
- project1.open(null);
- IPackageFragment pkg = getPackageFragment("second", "src", "pack2");
-
- IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[]
- {getJavaProject("JavaSearchBugs12")});
-
- search(
- pkg,
- ALL_OCCURRENCES,
- scope,
- this.resultCollector);
- String exp = "src/pack1/X11.java void pack1.X11.main(String[]) [pack2] EXACT_MATCH\n"
- +"src/pack2 pack2 EXACT_MATCH";
- assertSearchResults(
- exp,
- this.resultCollector);
-
- }
- finally {
- deleteProject("JavaSearchBugs12");
- deleteProject("second");
- }
-
-}
-/*
- * 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);
- }
-}
-
-} \ 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
new file mode 100644
index 0000000000..0c932c77af
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs13Tests.java
@@ -0,0 +1,1047 @@
+/*******************************************************************************
+ * 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;
+
+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);
+ }
+}
+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", "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);
+ }
+}
+
+
+/*
+ * 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);
+ 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.ENABLED);
+ 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.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);
+ }
+}
+/*
+ * 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);
+ }
+}
+
+/*
+ * 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/NullAnnotationModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
index 54d85a1b65..7dbfd9d928 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2016 GK Software AG and others.
+ * Copyright (c) 2011, 2019 GK Software AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -298,7 +298,7 @@ public class NullAnnotationModelTests extends ReconcilerTests {
"Buildpath problem: the type invalid, which is configured as a null annotation type, cannot be resolved\n" +
"----------\n");
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(p);
parser.setResolveBindings(true);
parser.setSource(unit);
@@ -361,7 +361,7 @@ public class NullAnnotationModelTests extends ReconcilerTests {
assertEquals("Should have no markers", 0, markers.length);
// Challenge CompilationUnitResolver:
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(p);
parser.setResolveBindings(true);
parser.setSource(unit);
@@ -432,7 +432,7 @@ public class NullAnnotationModelTests extends ReconcilerTests {
assertEquals("Unexpected marker path", "/P/p1/C1.java", markers[0].getResource().getFullPath().toString());
// Challenge CompilationUnitResolver:
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(p);
parser.setResolveBindings(true);
parser.setSource(unit);
@@ -485,7 +485,7 @@ public class NullAnnotationModelTests extends ReconcilerTests {
final ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null);
assertNoProblem(c1SourceString.toCharArray(), unit);
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setProject(p);
parser.setResolveBindings(true);
parser.setSource(unit);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
index 91ebdb5913..42c7614638 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java
@@ -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
@@ -79,7 +79,7 @@ public class ReconcilerTests extends ModifyingResourceTests {
}
}
- /*package*/ static final int JLS_LATEST = AST.JLS11;
+ /*package*/ static final int JLS_LATEST = AST.JLS13;
static class ReconcileParticipant extends CompilationParticipant {
IJavaElementDelta delta;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
index 4f85147bfc..02e1bd6089 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java
@@ -43,7 +43,7 @@ public class ReconcilerTests9 extends ModifyingResourceTests {
protected ICompilationUnit workingCopy;
protected ProblemRequestor problemRequestor;
- /*package*/ static final int JLS_LATEST = AST.JLS11;
+ /*package*/ static final int JLS_LATEST = AST.JLS13;
/**
*/
@@ -436,7 +436,7 @@ public void testBug540541() throws CoreException, IOException {
"}\n");
this.workingCopy = getCompilationUnit("client/src/p/X.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems",
"----------\n" +
"----------\n",
@@ -501,7 +501,7 @@ public void testBug543092() throws Exception {
this.workingCopy = getCompilationUnit("p/src/test/Test.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems",
"----------\n" +
"----------\n",
@@ -560,7 +560,7 @@ public void testBug543092b() throws Exception {
this.workingCopy = getCompilationUnit("p/src/test/Test.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems",
"----------\n" +
"1. ERROR in /p/src/test/Test.java (at line 3)\n" +
@@ -641,7 +641,7 @@ public void testBug544017() throws CoreException {
ICompilationUnit wc = getCompilationUnit(pathExample).getWorkingCopy(this.wcOwner, null);
wc.getBuffer().append(" ");
this.problemRequestor.initialize((sourceExample+" ").toCharArray());
- wc.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ wc.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems",
"----------\n" +
"----------\n",
@@ -676,7 +676,7 @@ public void testBug545687() throws CoreException, IOException {
this.problemRequestor.initialize(testSrc.toCharArray());
this.workingCopy = getCompilationUnit("testproj/src/test/Test.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems", "----------\n" + "----------\n", this.problemRequestor);
IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
@@ -792,7 +792,7 @@ public void testBug546315() throws Exception {
this.problemRequestor.initialize(testSource.toCharArray());
this.workingCopy = getCompilationUnit("p/src-test/test/Test.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems", "----------\n" + "----------\n", this.problemRequestor);
markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
@@ -843,7 +843,7 @@ public void testBug544306() throws Exception {
this.workingCopy.discardWorkingCopy();
this.workingCopy = getCompilationUnit("p2/src-test/p2/Test.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(testSource.toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
assertProblems("Expecting no problems", "----------\n" + "----------\n", this.problemRequestor);
this.workingCopy.discardWorkingCopy();
} finally {
@@ -934,7 +934,7 @@ public void testBug547113() throws CoreException {
this.problemRequestor.initialize(cSource.toCharArray());
this.workingCopy = getCompilationUnit("c/src/com/example/c/C.java").getWorkingCopy(this.wcOwner, null);
this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
- this.workingCopy.reconcile(AST_INTERNAL_JLS11, true, this.wcOwner, null);
+ this.workingCopy.reconcile(AST_INTERNAL_JLS13, true, this.wcOwner, null);
assertProblems("Expecting no problems",
"----------\n" +
"----------\n",
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
index 348ad9ccb1..992ad6f1bb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
@@ -41,7 +41,6 @@ public class RunCompletionModelTests extends junit.framework.TestCase {
COMPLETION_SUITES.add(CompletionTests9.class);
COMPLETION_SUITES.add(CompletionTests10.class);
COMPLETION_SUITES.add(CompletionTests11.class);
- COMPLETION_SUITES.add(CompletionTests12.class);
COMPLETION_SUITES.add(CompletionContextTests.class);
COMPLETION_SUITES.add(CompletionContextTests_1_5.class);
COMPLETION_SUITES.add(CompletionWithMissingTypesTests.class);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
index ae8f5e505d..26fe652407 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
@@ -104,10 +104,10 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
return createSuite(ASTRewritingStatementsTest.class);
}
- @Override
+ @Override
protected void setUp() throws Exception {
super.setUp();
- if (this.apiLevel == AST.JLS12 ) {
+ if (this.apiLevel == AST.JLS13 ) {
this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
this.project1.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
}
@@ -3615,7 +3615,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
assertTrue("Number of statements not 0", statements.size() == 0);
SwitchCase caseStatement1= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement1.setExpression(ast.newNumberLiteral("1"));
}
else {
@@ -3625,7 +3625,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
Statement statement1= ast.newReturnStatement();
SwitchCase caseStatement2= ast.newSwitchCase(); // default
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(null);
}
@@ -3650,7 +3650,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
// change case statement
SwitchCase caseStatement= (SwitchCase) statements.get(3);
Expression newCaseExpression= ast.newNumberLiteral("10");
- if (this.apiLevel != AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
} else {
List expressions = caseStatement.expressions();
@@ -3663,7 +3663,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(ast.newNumberLiteral("11"));
}
else {
@@ -3679,7 +3679,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(ast.newNumberLiteral("12"));
}
else {
@@ -3774,7 +3774,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
assertTrue("Number of statements not 0", statements.size() == 0);
SwitchCase caseStatement1= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement1.setExpression(ast.newNumberLiteral("1"));
}
else {
@@ -3784,7 +3784,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
Statement statement1= ast.newReturnStatement();
SwitchCase caseStatement2= ast.newSwitchCase(); // default
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(null);
}
@@ -3809,7 +3809,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
// change case statement
SwitchCase caseStatement= (SwitchCase) statements.get(3);
Expression newCaseExpression= ast.newNumberLiteral("10");
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
} else {
List expressions = caseStatement.expressions();
@@ -3822,7 +3822,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(ast.newNumberLiteral("11"));
}
else {
@@ -3839,7 +3839,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement2.setExpression(ast.newNumberLiteral("12"));
}
else {
@@ -4150,7 +4150,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
ExpressionStatement assignment = (ExpressionStatement)statements.get(1); // i= 1;:
SwitchCase switchCase = ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
switchCase.setExpression(ast.newNumberLiteral("2"));
}
else {
@@ -4298,7 +4298,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
ExpressionStatement assignment = (ExpressionStatement)statements.get(1); // i= 1;
SwitchCase switchCase = ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
switchCase.setExpression(ast.newNumberLiteral("2"));
}
else {
@@ -4622,7 +4622,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
SwitchCase caseStatement1= ast.newSwitchCase();
- if (this.apiLevel < AST.JLS12) {
+ if (this.apiLevel < AST.JLS13) {
caseStatement1.setExpression(ast.newNumberLiteral("100"));
} else {
caseStatement1.expressions().add(ast.newNumberLiteral("100"));
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
index 17754814ab..228b8872b4 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
@@ -54,15 +54,15 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
return createSuite(ASTRewritingSwitchExpressionsTest.class);
}
- @Override
+ @Override
protected void setUp() throws Exception {
super.setUp();
- if (this.apiLevel == AST.JLS12 ) {
+ if (this.apiLevel == AST.JLS13 ) {
this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
this.project1.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
- this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_12);
- this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_12);
- this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_12);
+ this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_13);
+ this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_13);
+ this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_13);
}
}
@@ -169,8 +169,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
+ @Deprecated
@SuppressWarnings("rawtypes")
- public void testSwitchExpressions_02_since_12() throws Exception {
+ public void _testSwitchExpressions_02_since_12() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -228,8 +229,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
assertEqualString(preview, buf.toString());
}
+ @Deprecated
@SuppressWarnings("rawtypes")
- public void testSwitchExpressions_03_since_12() throws Exception {
+ public void _testSwitchExpressions_03_since_12() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -315,7 +317,7 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
}
@SuppressWarnings("rawtypes")
- public void testSwitchStatement_Bug543720_since_12() throws Exception {
+ public void _testSwitchStatement_Bug543720_since_12() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -396,7 +398,7 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
assertEqualString(preview, buf.toString());
}
@SuppressWarnings("rawtypes")
- public void testSwitchExpressions_04_since_12() throws Exception {
+ public void _testSwitchExpressions_04_since_12() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s = "package test1;\n"+
"public class X {\n"+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
index 5437dbb065..4a2fb22113 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
@@ -83,9 +83,9 @@ public class ASTRewritingTest extends AbstractJavaModelTests {
/** @deprecated using deprecated code */
private final static int JLS10_INTERNAL = AST.JLS10;
- private final static int JLS12_INTERNAL = AST.JLS12;
+ private final static int JLS13_INTERNAL = AST.JLS13;
- private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS12_INTERNAL };
+ private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS13_INTERNAL };
private static final String ONLY_AST_STRING = "_only";
private static final String SINCE_AST_STRING = "_since";
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
index ecf0daa3ce..d0eb23b11b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
@@ -4959,7 +4959,7 @@ public class ImportRewriteTest extends AbstractJavaModelTests {
"}\n";
ICompilationUnit cu = pack1.createCompilationUnit("X.java", contents, false, null);
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setSource(cu);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
@@ -4984,7 +4984,7 @@ public class ImportRewriteTest extends AbstractJavaModelTests {
"}\n";
ICompilationUnit cu = pack1.createCompilationUnit("X.java", contents, false, null);
- ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS11);
+ ASTParser parser = ASTParser.newParser(AST_INTERNAL_LATEST);
parser.setSource(cu);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter12/.classpath b/org.eclipse.jdt.core.tests.model/workspace/Converter13/.classpath
index 3522bc0c3f..3522bc0c3f 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Converter12/.classpath
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter13/.classpath
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter12/.project b/org.eclipse.jdt.core.tests.model/workspace/Converter13/.project
index 663fb8d747..663fb8d747 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Converter12/.project
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter13/.project
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter12/src/X.java b/org.eclipse.jdt.core.tests.model/workspace/Converter13/src/X.java
index 5a1a8880f1..5a1a8880f1 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Converter12/src/X.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter13/src/X.java
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/A_out.java
index 683eafb167..f1db906b13 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/A_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/A_out.java
@@ -16,7 +16,7 @@ public class MyTest {
case 4: {
- // break missing, oh well...
+ // yield missing, oh well...
}
@@ -33,13 +33,13 @@ public class MyTest {
int c = switch (b) {
case 444:
- break a + b;
+ yield a + b;
case 555:
case 666:
doSoemthing();
- break 777;
+ yield 777;
default:
@@ -52,7 +52,7 @@ public class MyTest {
case 1 -> 6;
case 2 -> {
int f = a + b;
- break f * f;
+ yield f * f;
}
default -> 55;
};
@@ -79,32 +79,32 @@ public class MyTest {
doSomething(switch (a * b * c * d) {
case 888:
aaa();
- break bbb();
+ yield bbb();
// comment
case 999:
aaa();
- break bbb();
+ yield bbb();
// comment
case 101010:
aaa();
- break bbb();
+ yield bbb();
// comment
case 111111:
aaa();
- break bbb();
+ yield bbb();
// comment
case 121212:
aaa();
- break bbb();
+ yield bbb();
// comment
@@ -113,14 +113,14 @@ public class MyTest {
case 131313:
aaa();
- break bbb();
+ yield bbb();
// comment
// comment
default:
aaa();
- break bbb();
+ yield bbb();
});
}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/B_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/B_out.java
index b428dfcccd..68d73ba84b 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/B_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/B_out.java
@@ -12,7 +12,7 @@ public class MyTest {
doSomeOtherThing();
break;
case 4: {
- // break missing, oh well...
+ // yield missing, oh well...
}
case 5: {
doSomething(55);
@@ -25,11 +25,11 @@ public class MyTest {
int c = switch (b) {
case 444:
- break a + b;
+ yield a + b;
case 555:
case 666:
doSoemthing();
- break 777;
+ yield 777;
default:
doSomeOtherSomething();
return;
@@ -40,7 +40,7 @@ public class MyTest {
case 1 -> 6;
case 2 -> {
int f = a + b;
- break f * f;
+ yield f * f;
}
default -> 55;
};
@@ -63,37 +63,37 @@ public class MyTest {
doSomething(switch (a * b * c * d) {
case 888:
aaa();
- break bbb();
+ yield bbb();
// comment
case 999:
aaa();
- break bbb();
+ yield bbb();
// comment
case 101010:
aaa();
- break bbb();
+ yield bbb();
// comment
case 111111:
aaa();
- break bbb();
+ yield bbb();
// comment
case 121212:
aaa();
- break bbb();
+ yield bbb();
// comment
// comment
case 131313:
aaa();
- break bbb();
+ yield bbb();
// comment
// comment
default:
aaa();
- break bbb();
+ yield bbb();
});
}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/in.java
index 6072466362..967b5c9b78 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/in.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test390720/in.java
@@ -13,7 +13,7 @@ public class MyTest {
doSomeOtherThing();
break;
case 4: {
- // break missing, oh well...
+ // yield missing, oh well...
}
case 5: {
@@ -27,12 +27,12 @@ public class MyTest {
int c = switch (b) {
case 444:
- break a + b;
+ yield a + b;
case 555:
case 666:
doSoemthing();
- break 777;
+ yield 777;
default:
doSomeOtherSomething();
return;
@@ -43,7 +43,7 @@ public class MyTest {
case 1 -> 6;
case 2 -> {
int f = a + b;
- break f * f;
+ yield f * f;
}
default -> 55;
};
@@ -66,27 +66,27 @@ public class MyTest {
doSomething(switch (a * b * c * d) {
case 888:
aaa();
- break bbb();
+ yield bbb();
// comment
case 999:
aaa();
- break bbb();
+ yield bbb();
// comment
case 101010:
aaa();
- break bbb();
+ yield bbb();
// comment
case 111111:
aaa();
- break bbb();
+ yield bbb();
// comment
case 121212:
aaa();
- break bbb();
+ yield bbb();
// comment
@@ -94,12 +94,12 @@ public class MyTest {
case 131313:
aaa();
- break bbb();
+ yield bbb();
// comment
// comment
default:
aaa();
- break bbb();
+ yield bbb();
});
}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java
index 89ab5633ba..2e4f19b2bf 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java
@@ -31,7 +31,7 @@ public class C {
int value = switch (ABC) {
case A :
- break 1;
+ yield 1;
case B :
System.out.println("!!!");
return;
@@ -40,16 +40,16 @@ public class C {
case C , D , E , F , G :
case H , I , J : {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch (a.b.c.d(e.f.g.h())) {
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c , d.e , f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java
index 30ba3b5be8..9800b28ae7 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java
@@ -31,7 +31,7 @@ public class C {
int value = switch (ABC ) {
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -40,16 +40,16 @@ public class C {
case C,D,E,F,G:
case H,I,J: {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch (a.b.c.d(e.f.g.h()) ) {
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c,d.e,f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java
index b98e85a4d6..f7928100c0 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java
@@ -31,7 +31,7 @@ public class C {
int value = switch(ABC) {
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -40,16 +40,16 @@ public class C {
case C, D, E, F, G:
case H, I, J: {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch(a.b.c.d(e.f.g.h())) {
case a-> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java
index 49e0db739e..c9715995d5 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java
@@ -34,7 +34,7 @@ public class C {
int value = switch ( ABC)
{
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -43,17 +43,17 @@ public class C {
case C, D, E, F, G:
case H, I, J:{
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch ( a.b.c.d(e.f.g.h()))
{
case a ->{
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java
index d8bbd1a1f4..25f85e2c00 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java
@@ -37,7 +37,7 @@ public class C {
ABC
) {
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -46,10 +46,10 @@ public class C {
case C, D, E, F, G:
case H, I, J: {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default :
- break 6;
+ yield 6;
};
Object value2 = switch (
@@ -57,7 +57,7 @@ public class C {
) {
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java
index 6ad72c331f..27b34bdad4 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java
@@ -31,7 +31,7 @@ public class C {
int value = switch (ABC){
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -40,16 +40,16 @@ public class C {
case C, D, E, F, G:
case H, I, J:{
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch (a.b.c.d(e.f.g.h())){
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java
index aa05baad51..5a06a59163 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java
@@ -31,7 +31,7 @@ public class C {
int value = switch (ABC) {
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -40,16 +40,16 @@ public class C {
case C, D, E, F, G:
case H, I, J: {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
default:
- break 6;
+ yield 6;
};
Object value2 = switch (a.b.c.d(e.f.g.h())) {
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+ //
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java
index 7dfd080e19..96f93ec985 100644
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java
@@ -30,7 +30,7 @@ public class C {
int value = switch(ABC) {
case A:
- break 1;
+ yield 1;
case B:
System.out.println("!!!");
return;
@@ -38,15 +38,15 @@ public class C {
case C, D, E, F, G:
case H, I, J: {
System.out.println("@@@");
- break 3454366;
+ yield 3454366;
}
- default: break 6;
+ default: yield 6;
};
Object value2 = switch(a.b.c.d(e.f.g.h())) {
case a -> {
System.out.println("aaaaaaa");
- break "";
+ yield "";
}
case b + c, d.e, f("aaaaaaaaaaaa"//
+//
diff --git a/org.eclipse.jdt.core.tests.performance/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.performance/META-INF/MANIFEST.MF
index 539f46b01b..9b5cad8454 100644
--- a/org.eclipse.jdt.core.tests.performance/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.performance/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.performance
-Bundle-Version: 3.10.600.qualifier
+Bundle-Version: 3.10.650.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.performance,
diff --git a/org.eclipse.jdt.core.tests.performance/pom.xml b/org.eclipse.jdt.core.tests.performance/pom.xml
index e7be08995b..1aa7656e5f 100644
--- a/org.eclipse.jdt.core.tests.performance/pom.xml
+++ b/org.eclipse.jdt.core.tests.performance/pom.xml
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.performance</artifactId>
- <version>3.10.600-SNAPSHOT</version>
+ <version>3.10.650-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java
index fa5a8a2d8e..b4c03cd1c9 100644
--- a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java
+++ b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 Sven Strohschein and others.
+ * Copyright (c) 2016, 2019 Sven Strohschein and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -84,7 +84,7 @@ public class SecondaryTypesPerformanceTest extends PerformanceTestCase {
classpathList.add(testScratchArea);
for (int i = 0; i<10; ++i) {
- ASTParser parser = ASTParser.newParser(AST.JLS11);
+ ASTParser parser = ASTParser.newParser(AST.JLS13);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
diff --git a/org.eclipse.jdt.core/.settings/.api_filters b/org.eclipse.jdt.core/.settings/.api_filters
index 26e4f57056..f5f3fac15f 100644
--- a/org.eclipse.jdt.core/.settings/.api_filters
+++ b/org.eclipse.jdt.core/.settings/.api_filters
@@ -1,49 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jdt.core" version="2">
<resource path="compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java" type="org.eclipse.jdt.core.compiler.CategorizedProblem">
- <filter comment="To be addressed while merging 12" id="336658481">
+ <filter comment="PREVIEW RELATED" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.compiler.CategorizedProblem"/>
- <message_argument value="CAT_COMPLIANCE"/>
+ <message_argument value="CAT_PREVIEW_RELATED"/>
</message_arguments>
</filter>
</resource>
<resource path="compiler/org/eclipse/jdt/core/compiler/IProblem.java" type="org.eclipse.jdt.core.compiler.IProblem">
- <filter id="388194388">
+ <filter comment="BETA_JAVA13 addition of preview related base" id="388194388">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.compiler.IProblem"/>
<message_argument value="IgnoreCategoriesMask"/>
- <message_argument value="8388607"/>
+ <message_argument value="4194303"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="dom/org/eclipse/jdt/core/dom/ASTVisitor.java" type="org.eclipse.jdt.core.dom.ASTVisitor">
+ <filter comment="Not required as it is a part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.ASTVisitor"/>
+ <message_argument value="visit(SwitchExpression)"/>
</message_arguments>
</filter>
</resource>
<resource path="dom/org/eclipse/jdt/core/dom/BreakStatement.java" type="org.eclipse.jdt.core.dom.BreakStatement">
- <filter comment="For Java 12 support." id="336658481">
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.BreakStatement"/>
+ <message_argument value="getExpression()"/>
+ </message_arguments>
+ </filter>
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.BreakStatement"/>
+ <message_argument value="isImplicit()"/>
+ </message_arguments>
+ </filter>
+ <filter comment="preview feature - transient" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.BreakStatement"/>
+ <message_argument value="propertyDescriptors(int, boolean)"/>
+ </message_arguments>
+ </filter>
+ <filter comment="Not valid for Java 13" id="338944126">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.dom.BreakStatement"/>
- <message_argument value="EXPRESSION_PROPERTY"/>
+ <message_argument value="setExpression(Expression)"/>
</message_arguments>
</filter>
</resource>
<resource path="dom/org/eclipse/jdt/core/dom/SwitchCase.java" type="org.eclipse.jdt.core.dom.SwitchCase">
- <filter comment="For Java 12" id="336658481">
+ <filter comment="No more an API as part of preview feature" id="338944126">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.dom.SwitchCase"/>
- <message_argument value="EXPRESSIONS2_PROPERTY"/>
+ <message_argument value="expressions()"/>
</message_arguments>
</filter>
- <filter comment="For Java 12 Support - case -&gt;" id="336658481">
+ <filter comment="No more an API as part of preview feature" id="338944126">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.dom.SwitchCase"/>
- <message_argument value="SWITCH_LABELED_RULE_PROPERTY"/>
+ <message_argument value="isSwitchLabeledRule()"/>
+ </message_arguments>
+ </filter>
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchCase"/>
+ <message_argument value="setSwitchLabeledRule(boolean)"/>
</message_arguments>
</filter>
</resource>
- <resource path="model/org/eclipse/jdt/core/util/IClassFileReader.java" type="org.eclipse.jdt.core.util.IClassFileReader">
- <filter comment="default method added for getting nest members" id="404000815">
+ <resource path="dom/org/eclipse/jdt/core/dom/SwitchExpression.java" type="org.eclipse.jdt.core.dom.SwitchExpression">
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchExpression"/>
+ <message_argument value="getExpression()"/>
+ </message_arguments>
+ </filter>
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchExpression"/>
+ <message_argument value="propertyDescriptors(int)"/>
+ </message_arguments>
+ </filter>
+ <filter comment="preview feature - transient" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchExpression"/>
+ <message_argument value="propertyDescriptors(int, boolean)"/>
+ </message_arguments>
+ </filter>
+ <filter comment="No more an API as part of preview feature" id="338944126">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchExpression"/>
+ <message_argument value="setExpression(Expression)"/>
+ </message_arguments>
+ </filter>
+ <filter comment="Only for Java 13" id="338944126">
<message_arguments>
- <message_argument value="org.eclipse.jdt.core.util.IClassFileReader"/>
- <message_argument value="getNestMembersAttribute()"/>
+ <message_argument value="org.eclipse.jdt.core.dom.SwitchExpression"/>
+ <message_argument value="statements()"/>
</message_arguments>
</filter>
</resource>
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
index 43131531bc..daf0b505bd 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
@@ -2195,6 +2195,16 @@ public void configure(String[] argv) {
mode = DEFAULT;
continue;
}
+ if (currentArg.equals("-13") || currentArg.equals("-13.0")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (didSpecifyCompliance) {
+ throw new IllegalArgumentException(
+ this.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$
+ }
+ didSpecifyCompliance = true;
+ this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13);
+ mode = DEFAULT;
+ continue;
+ }
if (currentArg.equals("-d")) { //$NON-NLS-1$
if (this.destinationPath != null) {
StringBuffer errorMessage = new StringBuffer();
@@ -2753,6 +2763,8 @@ public void configure(String[] argv) {
this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11);
} else if (currentArg.equals("12") || currentArg.equals("12.0")) { //$NON-NLS-1$//$NON-NLS-2$
this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ } else if (currentArg.equals("13") || currentArg.equals("13.0")) { //$NON-NLS-1$//$NON-NLS-2$
+ this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_13);
}
else if (currentArg.equals("jsr14")) { //$NON-NLS-1$
this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14);
@@ -2844,6 +2856,8 @@ public void configure(String[] argv) {
this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11);
} else if (currentArg.equals("12") || currentArg.equals("12.0")) { //$NON-NLS-1$//$NON-NLS-2$
this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
+ } else if (currentArg.equals("13") || currentArg.equals("13.0")) { //$NON-NLS-1$//$NON-NLS-2$
+ this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13);
} else {
throw new IllegalArgumentException(this.bind("configure.source", currentArg)); //$NON-NLS-1$
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
index 38eaad8ce3..9a0c3d312a 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contribution for
@@ -99,6 +99,7 @@ public class CompletionParser extends AssistParser {
protected static final int K_AFTER_NAME_IN_PROVIDES_STATEMENT = COMPLETION_PARSER + 49;
protected static final int K_AFTER_WITH_IN_PROVIDES_STATEMENT = COMPLETION_PARSER + 50;
protected static final int K_INSIDE_OPENS_STATEMENT = COMPLETION_PARSER + 51;
+ pro