Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-03-20 05:34:08 -0400
committerJay Arthanareeswaran2019-03-20 05:34:08 -0400
commit896cb38596980efacd9f1a3858de3d5249bab258 (patch)
tree8381947296d8b2ddc8499bc9d61ee6a45c4583e3
parentb9957bd06da31c58841b8ad50731877e58c32071 (diff)
parent9d41eef9c57e4ff00f30312ccf1fdfdfc61daa21 (diff)
downloadeclipse.jdt.core-896cb38596980efacd9f1a3858de3d5249bab258.tar.gz
eclipse.jdt.core-896cb38596980efacd9f1a3858de3d5249bab258.tar.xz
eclipse.jdt.core-896cb38596980efacd9f1a3858de3d5249bab258.zip
Merge branch 'BETA_JAVA_12' to master for 4.12 builds
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/.classpath2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/build.properties5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin246813 -> 257765 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar (renamed from org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar)bin109915 -> 109915 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java391
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java23
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java5
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java7
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java2
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java4
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java1
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java10
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java113
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java8
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java16
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java8
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java7
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java8
-rw-r--r--org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/JrtFileSystem.java8
-rw-r--r--org.eclipse.jdt.core.internal.tools/.classpath1
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/disassembler/Disassembler.java36
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/CodePointsBuilder.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/Environment.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/FileEncoder.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierPartResources.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierStartResources.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/PartEnvironment.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/StartEnvironment.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/TableBuilder.java13
-rw-r--r--org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/UnicodeResourceGenerator.java13
-rw-r--r--org.eclipse.jdt.core.tests.compiler/pom.xml32
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java129
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java34
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.java1070
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java26
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java25
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java29
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java3
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java629
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java1940
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java28
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java8
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java115
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java226
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java30
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java50
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java176
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java2365
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java24
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java22
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.java65
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java8
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java43
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java51
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jarbin0 -> 22094 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.zipbin0 -> 12320 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zipbin0 -> 12320 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jarbin14586 -> 14680 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zipbin9140 -> 11529 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/jclMin12.jarbin0 -> 21029 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/JCL/jclMin12src.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.java87
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java76
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java391
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java91
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java6
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java13
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java79
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java41
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java856
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java3
-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/JavaSearchTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java37
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12.java608
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java233
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java848
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java71
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter12/.classpath6
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter12/.project17
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter12/src/X.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/A_out.java72
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/B_out.java72
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/C_out.java72
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/D_out.java76
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/E_out.java80
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/F_out.java72
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/G_out.java72
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543818/in.java66
-rw-r--r--org.eclipse.jdt.core/.settings/.api_filters64
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java4
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java13
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java10
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java2
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java20
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionJavadocParser.java2
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java45
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java17
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java2
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java31
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java35
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java79
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java120
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java23
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java30
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java25
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java53
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java604
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java327
-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/codegen/CodeStream.java33
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java49
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java27
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/Constant.java1
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java28
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java1006
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/ParserBasicInformation.java34
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java17
-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.java190
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser1.rscbin33634 -> 34466 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser10.rscbin582 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser11.rscbin582 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser12.rscbin582 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser13.rscbin582 -> 596 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser14.rscbin2322 -> 2360 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser15.rscbin1466 -> 1490 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser16.rscbin2306 -> 2334 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser17.rscbin852 -> 868 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser18.rscbin7491 -> 7796 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser19.rsc4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser2.rscbin31930 -> 32730 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser20.rscbin16468 -> 16850 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser21.rscbin6816 -> 6944 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser22.rscbin778 -> 796 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.rscbin778 -> 796 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser3.rscbin2306 -> 2334 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser4.rscbin3356 -> 3460 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser5.rscbin2306 -> 2334 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser6.rscbin1380 -> 1416 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser7.rscbin258 -> 260 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser8.rscbin778 -> 796 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/parser9.rscbin14858 -> 15468 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/readableNames.props9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/part0.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/part1.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/part14.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/part2.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/start0.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/start1.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/unicode11/start2.rscbin0 -> 8192 bytes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java140
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties20
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/JRTUtil.java23
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java59
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java119
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java44
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java28
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java3
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java36
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java121
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java14
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java9
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Expression.java3
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java148
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java237
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java93
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java168
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java82
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java5
-rw-r--r--org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java8
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java68
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java10
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java36
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java58
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java39
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java9
-rw-r--r--org.eclipse.jdt.core/grammar/java.g56
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java39
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java6
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JrtPackageFragmentRoot.java6
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java7
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrtWithReleaseOption.java15
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java4
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJrtToIndex.java6
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java9
237 files changed, 16204 insertions, 1330 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath
index 3592a9572a..8102373411 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="java10/java10api.jar"/>
+ <classpathentry kind="lib" path="lib/java10api.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 cd2f132a06..f08a46a4dd 100644
--- a/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
@@ -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: java10/java10api.jar,
+Bundle-ClassPath: lib/java10api.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 e872602914..e9a85ccd3b 100644
--- a/org.eclipse.jdt.compiler.apt.tests/build.properties
+++ b/org.eclipse.jdt.compiler.apt.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2006, 2018 BEA Systems Inc. and others
+# Copyright (c) 2006, 2019 BEA Systems Inc. and others
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -23,9 +23,8 @@ bin.includes = about.html,\
test.xml,\
META-INF/,\
resources/,\
- java10/,\
lib/,\
.
src.includes = about.html
compilerArg=-proc:none
-jars.extra.classpath = java10/java10api.jar
+jars.extra.classpath = lib/java10api.jar
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index 363e26f2b8..89b229279b 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/java10/java10api.jar b/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar
index 464b69134f..464b69134f 100644
--- a/org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/java10api.jar
Binary files differ
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 8b8bccf832..4d8344550a 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
@@ -1,3 +1,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 \ No newline at end of file
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java11ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor \ No newline at end of file
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
new file mode 100644
index 0000000000..912464f664
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java12ElementProcessor.java
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.Collections;
+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.compiler.apt.tests.processors.base.BaseProcessor;
+
+/**
+ * A processor that explores the java 9 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 Java12ElementProcessor 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 {
+ testRootElements1();
+ }
+
+ public void testRootElements1() throws IOException {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ List<String> types = new ArrayList<>();
+ List<String> modules = new ArrayList<>();
+ ModuleElement mod1 = null, mod2 = null, mod3 = null;
+ for (Element element : rootElements) {
+ Element root = getRoot(element);
+ String modName = null;
+ ModuleElement mod = null;
+ if (element instanceof ModuleElement) {
+ mod = (ModuleElement) element;
+ modName = mod.getQualifiedName().toString();
+ if (!modules.contains(modName) && !modName.equals("java.base"))
+ modules.add(modName);
+ assertNull("module should not have an enclosing element", root);
+ } else {
+ if (element instanceof TypeElement) {
+ types.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ assertTrue("Should be a module element", (root instanceof ModuleElement));
+ mod = (ModuleElement) root;
+ modName = mod.getQualifiedName().toString();
+ assertFalse("should be a named module", mod.isUnnamed());
+ String string = mod.getQualifiedName().toString();
+ if (!modules.contains(string) && !modName.equals("java.base"))
+ modules.add(string);
+ }
+ if (modName.equals("module.main")) {
+ mod1 = mod;
+ } else if (modName.equals("module.readable.one")) {
+ mod2 = mod;
+ } else if (modName.equals("module.readable.two")) {
+ mod3 = mod;
+ }
+ }
+ Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
+ Collections.sort(modules, (x, y) -> x.compareTo(y));
+ assertEquals("incorrect no of modules in root elements in in "+ this.mode + " mode", 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one, module.readable.two]", modules.toString());
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod3);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD.same, ]", getElementsAsString(mod3.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD.same, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[lang.MOD, ]", getElementsAsString(mod1.getEnclosedElements()));
+ }
+
+ public void testRootElements2() throws IOException {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ List<String> types = new ArrayList<>();
+ List<String> modules = new ArrayList<>();
+ ModuleElement mod1 = null, mod2 = null, mod3 = null;
+ for (Element element : rootElements) {
+ Element root = getRoot(element);
+ String modName = null;
+ ModuleElement mod = null;
+ if (element instanceof ModuleElement) {
+ mod = (ModuleElement) element;
+ modName = mod.getQualifiedName().toString();
+ if (!modules.contains(modName) && !modName.equals("java.base"))
+ modules.add(modName);
+ assertNull("module should not have an enclosing element", root);
+ } else {
+ if (element instanceof TypeElement) {
+ types.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ assertTrue("Should be a module element", (root instanceof ModuleElement));
+ mod = (ModuleElement) root;
+ modName = mod.getQualifiedName().toString();
+ assertFalse("should be a named module", mod.isUnnamed());
+ String string = mod.getQualifiedName().toString();
+ if (!modules.contains(string) && !modName.equals("java.base"))
+ modules.add(string);
+ }
+ if (modName.equals("module.main")) {
+ mod1 = mod;
+ } else if (modName.equals("module.readable.one")) {
+ mod2 = mod;
+ } else if (modName.equals("module.readable.two")) {
+ mod3 = mod;
+ }
+ }
+ Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
+ Collections.sort(modules, (x, y) -> x.compareTo(y));
+ assertEquals("incorrect no of modules in root elements in "+ this.mode + " mode", this.isBinaryMode ? 2 : 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one" +
+ (this.isBinaryMode ? "" : ", module.readable.two") + "]", modules.toString());
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my.mod, ]", getElementsAsString(mod1.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my.mod.same, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
+ if (!this.isBinaryMode) {
+ assertNotNull("module should not be null ", mod3);
+ assertEquals("Incorrect enclosed packages ", "[]", getElementsAsString(mod3.getEnclosedElements()));
+ }
+ }
+ public void testRootElements3() throws IOException {
+ Set<? extends Element> rootElements = this.roundEnv.getRootElements();
+ List<String> types = new ArrayList<>();
+ List<String> modules = new ArrayList<>();
+ ModuleElement mod1 = null, mod2 = null, mod3 = null;
+ for (Element element : rootElements) {
+ Element root = getRoot(element);
+ String modName = null;
+ ModuleElement mod = null;
+ if (element instanceof ModuleElement) {
+ mod = (ModuleElement) element;
+ modName = mod.getQualifiedName().toString();
+ if (!modules.contains(modName) && !modName.equals("java.base"))
+ modules.add(modName);
+ assertNull("module should not have an enclosing element", root);
+ } else {
+ if (element instanceof TypeElement) {
+ types.add(((TypeElement) element).getQualifiedName().toString());
+ }
+ assertTrue("Should be a module element", (root instanceof ModuleElement));
+ mod = (ModuleElement) root;
+ modName = mod.getQualifiedName().toString();
+ assertFalse("should be a named module", mod.isUnnamed());
+ String string = mod.getQualifiedName().toString();
+ if (!modules.contains(string) && !modName.equals("java.base"))
+ modules.add(string);
+ }
+ if (modName.equals("module.main")) {
+ mod1 = mod;
+ } else if (modName.equals("module.readable.one")) {
+ mod2 = mod;
+ } else if (modName.equals("module.readable.two")) {
+ mod3 = mod;
+ }
+ }
+ Collections.sort(types, (x, y) -> x.compareTo(y)); //unused as of now
+ Collections.sort(modules, (x, y) -> x.compareTo(y));
+ assertEquals("incorrect no of modules in root elements in "+ this.mode + " mode", 3, modules.size());
+ assertEquals("incorrect modules among root elements in "+ this.mode + " mode", "[module.main, module.readable.one, module.readable.two]", modules.toString());
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod1);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod, ]", getElementsAsString(mod1.getEnclosedElements()));
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod.samePackage, ]", getElementsAsString(mod2.getEnclosedElements()));
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod2);
+ assertNotNull("module should not be null in "+ this.mode + " mode", mod3);
+ assertEquals("Incorrect enclosed packages in "+ this.mode + " mode", "[my1.mod.samePackage, ]", getElementsAsString(mod3.getEnclosedElements()));
+ }
+ private Element getRoot(Element elem) {
+ Element enclosingElement = elem.getEnclosingElement();
+ while (enclosingElement != null) {
+ if (enclosingElement instanceof ModuleElement) {
+ return enclosingElement;
+ }
+ enclosingElement = enclosingElement.getEnclosingElement();
+ }
+ return enclosingElement;
+ }
+
+ @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/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
index 0b400a7fd5..a412679a7f 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
@@ -51,6 +51,7 @@ import javax.lang.model.type.TypeMirror;
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
import org.eclipse.jdt.compiler.apt.tests.processors.util.TestDirectiveVisitor;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
/**
* A processor that explores the java 9 specific elements and validates the lambda and
@@ -63,6 +64,7 @@ public class Java9ElementProcessor extends BaseProcessor {
boolean reportSuccessAlready = true;
RoundEnvironment roundEnv = null;
Messager _messager = null;
+ boolean isJre12;
boolean isJre11;
boolean isJre10;
@Override
@@ -70,19 +72,14 @@ public class Java9ElementProcessor extends BaseProcessor {
super.init(processingEnv);
_typeUtils = processingEnv.getTypeUtils();
_messager = processingEnv.getMessager();
- try {
- SourceVersion.valueOf("RELEASE_11");
+ String property = System.getProperty("java.specification.version");
+ if (property.equals(CompilerOptions.VERSION_10)) {
this.isJre10 = true;
+ } else if (property.equals(CompilerOptions.VERSION_11)) {
this.isJre11 = true;
- } catch(IllegalArgumentException iae) {
- }
- if (!this.isJre11) {
- try {
- SourceVersion.valueOf("RELEASE_10");
- this.isJre10 = true;
- } catch(IllegalArgumentException iae) {
- }
- }
+ } else if (property.equals(CompilerOptions.VERSION_12)) {
+ this.isJre12 = true;
+ }
}
// Always return false from this processor, because it supports "*".
// The return value does not signify success or failure!
@@ -476,7 +473,7 @@ public class Java9ElementProcessor extends BaseProcessor {
assertNotNull("java.base module null", base);
List<? extends Directive> directives = base.getDirectives();
List<Directive> filterDirective = filterDirective(directives, DirectiveKind.USES);
- assertEquals("incorrect no of uses", this.isJre11? 33 : 34, filterDirective.size());
+ assertEquals("incorrect no of uses", (this.isJre11 || this.isJre12) ? 33 : 34, filterDirective.size());
}
/*
* Test java.base module can be loaded and verify its 'provides' attributes
@@ -530,7 +527,7 @@ public class Java9ElementProcessor extends BaseProcessor {
assertNotNull("java.sql module null", base);
List<? extends Directive> directives = base.getDirectives();
List<Directive> filterDirective = filterDirective(directives, DirectiveKind.REQUIRES);
- assertEquals("Incorrect no of requires", this.isJre11 ? 4 : 3, filterDirective.size());
+ assertEquals("Incorrect no of requires", (this.isJre11 || this.isJre12) ? 4 : 3, filterDirective.size());
RequiresDirective req = null;
for (Directive directive : filterDirective) {
if (((RequiresDirective) directive).getDependency().getQualifiedName().toString().equals("java.logging")) {
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java
new file mode 100644
index 0000000000..c11e8d9972
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/lang/MOD/Main.java
@@ -0,0 +1,8 @@
+package lang.MOD;
+
+class MyClass { static int meth(lang.MOD.same.SomeType arg) { return arg.value; } }
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java
new file mode 100644
index 0000000000..fd0dc7b74d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.main/module-info.java
@@ -0,0 +1,5 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports lang.MOD;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java
new file mode 100644
index 0000000000..f7b1468bfa
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/lang/MOD/same/SomeType.java
@@ -0,0 +1,7 @@
+package lang.MOD.same;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java
new file mode 100644
index 0000000000..c0dc95931d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.one/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.one {
+ exports lang.MOD.same to module.main;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java
new file mode 100644
index 0000000000..33a983543d
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/lang/MOD/same/SomeType.java
@@ -0,0 +1,4 @@
+package lang.MOD.same;
+
+public class SomeType {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java
new file mode 100644
index 0000000000..df9b457d55
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules2/module.readable.two/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.two {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java
new file mode 100644
index 0000000000..b755208a1b
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/module-info.java
@@ -0,0 +1,5 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports my.mod;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java
new file mode 100644
index 0000000000..b60ff762a8
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.main/my/mod/Main.java
@@ -0,0 +1,10 @@
+package my.mod;
+
+import java.io.PrintStream;
+
+class MyClass { static int meth(my.mod.same.SomeType arg) { return arg.value; } }
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java
new file mode 100644
index 0000000000..75fa2b7cc1
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.one {
+ exports my.mod.same to module.main;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java
new file mode 100644
index 0000000000..8315b02925
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.one/my/mod/same/SomeType.java
@@ -0,0 +1,7 @@
+package my.mod.same;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java
new file mode 100644
index 0000000000..df9b457d55
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules3/module.readable.two/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.two {
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java
new file mode 100644
index 0000000000..a0c0e261a0
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/module-info.java
@@ -0,0 +1,6 @@
+module module.main {
+ requires module.readable.one;
+ requires module.readable.two;
+ exports my1.mod;
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java
new file mode 100644
index 0000000000..c8780aa034
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.main/my1/mod/Main.java
@@ -0,0 +1,8 @@
+package my1.mod;
+
+import my1.mod.samePackage.*;
+
+public class Main {
+ public static void main(String argv[]) {
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java
new file mode 100644
index 0000000000..f334952c59
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/module-info.java
@@ -0,0 +1,2 @@
+module module.readable.one {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java
new file mode 100644
index 0000000000..c06c6e8900
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.one/my1/mod/samePackage/SomeType.java
@@ -0,0 +1,4 @@
+package my1.mod.samePackage;
+
+public class SomeType {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java
new file mode 100644
index 0000000000..475fe375bb
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/module-info.java
@@ -0,0 +1,3 @@
+module module.readable.two {
+ exports my1.mod.samePackage;
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java
new file mode 100644
index 0000000000..9d543b4606
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/mod_locations/modules4/module.readable.two/my1/mod/samePackage/SomeType.java
@@ -0,0 +1,8 @@
+package my1.mod.samePackage;
+
+public class SomeType {
+ public static class NestedClass {
+ }
+ public static int value = 1;
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
index 9491959c63..413a63d6bc 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java
@@ -36,6 +36,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(Java8ElementsTests.class);
suite.addTestSuite(Java9ElementsTests.class);
suite.addTestSuite(Java11ElementsTests.class);
+ suite.addTestSuite(Java12ElementsTests.class);
suite.addTestSuite(AnnotationProcessorTests.class);
return suite;
}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
index 576b5f57c5..75bad9352d 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
@@ -122,11 +122,11 @@ public class BatchTestUtils {
}
public static void compileInModuleMode(JavaCompiler compiler, List<String> options, String processor,
- File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule) {
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule) throws IOException {
compileInModuleMode(compiler, options, processor, targetFolder, listener, multiModule, true);
}
public static void compileInModuleMode(JavaCompiler compiler, List<String> options, String processor,
- File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule, boolean processBinariesAgain) {
+ File targetFolder, DiagnosticListener<? super JavaFileObject> listener, boolean multiModule, boolean processBinariesAgain) throws IOException {
StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
Iterable<? extends File> location = manager.getLocation(StandardLocation.CLASS_PATH);
// create new list containing inputfile
@@ -145,7 +145,7 @@ public class BatchTestUtils {
copyOptions.add(_tmpBinFolderName);
copyOptions.add("-s");
copyOptions.add(_tmpGenFolderName);
- addModuleProcessorPath(copyOptions, getSrcFolderName(), multiModule);
+ addModuleProcessorPath(copyOptions, targetFolder.getAbsolutePath(), multiModule);
copyOptions.add("-XprintRounds");
CompilationTask task = compiler.getTask(printWriter, manager, listener, copyOptions, null, units);
Boolean result = task.call();
@@ -154,6 +154,8 @@ public class BatchTestUtils {
String errorOutput = stringWriter.getBuffer().toString();
System.err.println("Compilation failed: " + errorOutput);
junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
+ } else {
+ junit.framework.TestCase.assertEquals("succeeded", System.getProperty(processor));
}
if (!processBinariesAgain) {
return;
@@ -164,6 +166,7 @@ public class BatchTestUtils {
System.clearProperty(processor);
copyOptions = new ArrayList<>();
copyOptions.addAll(options);
+ copyOptions.add("-Abinary");
copyOptions.add("-cp");
copyOptions.add(_jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
copyOptions.add("--processor-module-path");
@@ -257,6 +260,7 @@ public class BatchTestUtils {
System.clearProperty(processor);
copyOptions = new ArrayList<>();
copyOptions.addAll(options);
+ copyOptions.add("-Abinary");
copyOptions.add("-cp");
copyOptions.add(_tmpBinFolderName + File.pathSeparator + _jls8ProcessorJarPath + File.pathSeparator + _tmpGenFolderName);
copyOptions.add("-processorpath");
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
new file mode 100644
index 0000000000..7d2b1aedfe
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java12ElementsTests.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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 javax.tools.ToolProvider;
+
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
+import junit.framework.TestCase;
+
+public class Java12ElementsTests extends TestCase {
+ private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java12ElementProcessor";
+
+ public void testRootElements1Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements1", null, "modules2");
+ }
+ public void testRootElements1() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements1", null, "modules2");
+ }
+ public void testRootElements2Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements2", null, "modules3");
+ }
+ public void testRootElements2() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements2", null, "modules3");
+ }
+ public void testRootElements3Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements3", null, "modules4");
+ }
+ public void testRootElements3() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, MODULE_PROC, "12", "testRootElements3", null, "modules4");
+ }
+
+ protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
+ if (!canRunJava12()) {
+ 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);
+ }
+ 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 canRunJava12() {
+ try {
+ SourceVersion.valueOf("RELEASE_12");
+ } 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/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
index 185dfd8f8a..d4aca24a4c 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java
@@ -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
@@ -34,6 +34,7 @@ import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
@@ -235,6 +236,11 @@ public class RoundEnvImpl implements RoundEnvironment
throw new IllegalArgumentException("Top-level type binding could not be converted to element: " + typeBinding); //$NON-NLS-1$
}
elements.add(element);
+ ModuleBinding binding = typeBinding.module();
+ if (binding != null) {
+ Element m = _factory.newElement(binding);
+ elements.add(m);
+ }
}
}
_rootElements = elements;
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
index adda859990..86183925d5 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 IBM Corporation and others.
+ * Copyright (c) 2018, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*
@@ -90,8 +90,18 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
for (PackageBinding p : packs) {
if (p == null)
continue;
- if (!p.hasCompilationUnit(true))
+ if (p instanceof SplitPackageBinding) {
+ // select from incarnations the unique package containing CUs, if any:
+ for (PackageBinding incarnation : ((SplitPackageBinding) p).incarnations) {
+ if (incarnation.enclosingModule == module && incarnation.hasCompilationUnit(true)) {
+ unique.add(getModulesPackageBinding(p));
+ }
+ }
continue;
+ } else {
+ if (!p.hasCompilationUnit(true))
+ continue;
+ }
unique.add(getModulesPackageBinding(p));
}
if (module.isUnnamed()) {
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
index b23b9f4192..a34fbbf62e 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
@@ -92,12 +92,8 @@ public class JrtFileSystem extends Archive {
}
@Override
- public FileVisitResult visitModule(Path mod) throws IOException {
- String name = mod.getFileName().toString();
- if (name.endsWith("/")) { //$NON-NLS-1$
- name = name.substring(0, name.length() - 1);
- }
- JrtFileSystem.this.modulePathMap.put(name, mod);
+ public FileVisitResult visitModule(Path path, String name) throws IOException {
+ JrtFileSystem.this.modulePathMap.put(name, path);
return FileVisitResult.CONTINUE;
}
}, JRTUtil.NOTIFY_MODULES);
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
index 4b3d38a849..b942161690 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java
@@ -119,9 +119,10 @@ public class EclipseCompiler implements JavaCompiler {
eclipseCompiler2.fileManager = this.getStandardFileManager(someDiagnosticListener, null, null);
}
- eclipseCompiler2.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11);
- eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11);
- eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11);
+ String latest = CompilerOptions.getLatestVersion();
+ eclipseCompiler2.options.put(CompilerOptions.OPTION_Compliance, latest);
+ eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, latest);
+ eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, latest);
ArrayList<String> allOptions = new ArrayList<>();
if (options != null) {
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
index 05fcedbc18..cd80ce6633 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java
@@ -1365,10 +1365,10 @@ public class EclipseFileManager implements StandardJavaFileManager {
// FIXME: same for module source path?
Map<String, String> options = new HashMap<>();
// FIXME: Find a way to get the options from the EclipseCompiler and pass it to the parser.
- // FIXME: need to be the latest and not hardcoded value
- options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11);
- options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11);
- options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11);
+ String latest = CompilerOptions.getLatestVersion();
+ options.put(CompilerOptions.OPTION_Compliance, latest);
+ options.put(CompilerOptions.OPTION_Source, latest);
+ options.put(CompilerOptions.OPTION_TargetPlatform, latest);
CompilerOptions compilerOptions = new CompilerOptions(options);
ProblemReporter problemReporter =
new ProblemReporter(
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/JrtFileSystem.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/JrtFileSystem.java
index 57e6bd9a82..a140e15240 100644
--- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/JrtFileSystem.java
+++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/JrtFileSystem.java
@@ -92,12 +92,8 @@ public class JrtFileSystem extends Archive {
}
@Override
- public FileVisitResult visitModule(Path mod) throws IOException {
- String name = mod.getFileName().toString();
- if (name.endsWith("/")) { //$NON-NLS-1$
- name = name.substring(0, name.length() - 1);
- }
- JrtFileSystem.this.modulePathMap.put(name, mod);
+ public FileVisitResult visitModule(Path path, String name) throws IOException {
+ JrtFileSystem.this.modulePathMap.put(name, path);
return FileVisitResult.CONTINUE;
}
}, JRTUtil.NOTIFY_MODULES);
diff --git a/org.eclipse.jdt.core.internal.tools/.classpath b/org.eclipse.jdt.core.internal.tools/.classpath
index 01836c4842..ea3258e180 100644
--- a/org.eclipse.jdt.core.internal.tools/.classpath
+++ b/org.eclipse.jdt.core.internal.tools/.classpath
@@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jdt.core"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/disassembler/Disassembler.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/disassembler/Disassembler.java
new file mode 100644
index 0000000000..33c46594a7
--- /dev/null
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/disassembler/Disassembler.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.internal.tools.disassembler;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
+import org.eclipse.jdt.core.util.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.util.Util;
+
+public class Disassembler {
+
+ public static void main(String[] args) throws IOException, ClassFormatException {
+ if (args.length != 1) {
+ System.out.println("Usage: Disassembler <path to a .class file>"); //$NON-NLS-1$
+ return;
+ }
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ byte[] classFileBytes = Util.getFileByteContent(new File(args[0]));
+ System.out.println(disassembler.disassemble(classFileBytes, System.getProperty("line.separator"), org.eclipse.jdt.core.util.ClassFileBytesDisassembler.SYSTEM)); //$NON-NLS-1$
+ }
+
+}
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/CodePointsBuilder.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/CodePointsBuilder.java
index b86075dede..317dcc5dd2 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/CodePointsBuilder.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/CodePointsBuilder.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.text.DecimalFormat;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/Environment.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/Environment.java
index e2fa003283..fa82934438 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/Environment.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/Environment.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
public abstract class Environment {
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/FileEncoder.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/FileEncoder.java
index ad189dde3d..6347059bad 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/FileEncoder.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/FileEncoder.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.io.DataOutputStream;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierPartResources.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierPartResources.java
index 8ed6e75dd0..2cb3293535 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierPartResources.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierPartResources.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.io.IOException;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierStartResources.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierStartResources.java
index d60b983090..79be18c401 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierStartResources.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/GenerateIdentifierStartResources.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.io.IOException;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/PartEnvironment.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/PartEnvironment.java
index 1abf8350f1..7a4f43237d 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/PartEnvironment.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/PartEnvironment.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.util.HashSet;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/StartEnvironment.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/StartEnvironment.java
index ec6b50ad87..7d447138ab 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/StartEnvironment.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/StartEnvironment.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.util.HashSet;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/TableBuilder.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/TableBuilder.java
index 870d3eb1b3..0eaa24b157 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/TableBuilder.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/TableBuilder.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.io.File;
diff --git a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/UnicodeResourceGenerator.java b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/UnicodeResourceGenerator.java
index 4d26774271..adda83d343 100644
--- a/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/UnicodeResourceGenerator.java
+++ b/org.eclipse.jdt.core.internal.tools/src/org/eclipse/jdt/core/internal/tools/unicode/UnicodeResourceGenerator.java
@@ -1,3 +1,16 @@
+/*******************************************************************************
+ * 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.internal.tools.unicode;
import java.io.IOException;
diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml
index b28fd33d97..f762fdd09c 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -37,6 +37,7 @@
<includes>
<include>org/eclipse/jdt/core/tests/compiler/parser/TestAll.class</include>
<include>org/eclipse/jdt/core/tests/compiler/regression/TestAll.class</include>
+ <include>org/eclipse/jdt/core/tests/eval/TestAll.class</include>
</includes>
<argLine>${tycho.surefire.argLine}</argLine>
</configuration>
@@ -137,6 +138,37 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-12</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-12</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-12/configure -->
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12</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 4fb966bd6b..28d1790c30 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -27,7 +27,7 @@ public class ComplianceDiagnoseTest extends AbstractRegressionTest {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which does not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "test0061" };
+// TESTS_NAMES = new String[] { "testBug531714" };
// TESTS_NUMBERS = new int[] { 50 };
// TESTS_RANGE = new int[] { 21, 50 };
}
@@ -1250,12 +1250,22 @@ public void test0027() {
};
String expected13ProblemLog =
- "----------\n" +
- "1. ERROR in X.java (at line 3)\n" +
- " for(Object o : switch){\n" +
- " ^\n" +
- "Syntax error, insert \"; ; ) Statement\" to complete BlockStatements\n" +
- "----------\n";
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " for(Object o : switch){\n" +
+ " ^\n" +
+ "Syntax error on token \":\", delete this token\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 3)\n" +
+ " for(Object o : switch){\n" +
+ " ^\n" +
+ "Syntax error, insert \": Expression )\" to complete EnhancedForStatementHeader\n" + // FIXME: bogus suggestion, this rule is compliance 1.5
+ "----------\n" +
+ "3. ERROR in X.java (at line 3)\n" +
+ " for(Object o : switch){\n" +
+ " ^\n" +
+ "Syntax error, insert \"Statement\" to complete BlockStatements\n" +
+ "----------\n";
String expected14ProblemLog =
expected13ProblemLog;
@@ -3510,4 +3520,107 @@ public void testBug440285() {
"Type arguments are not allowed here\n" +
"----------\n");
}
+public void testBug531714_001() {
+ if (this.complianceLevel >= ClassFileConstants.JDK12)
+ return;
+ 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" +
+ "The preview feature Switch Expressions is only available with source level 12 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" +
+ "----------\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" +
+ "----------\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" +
+ "----------\n";
+
+ runComplianceParserTest(
+ testFiles,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog
+ );
+}
+public void testBug531714_002() {
+ if (this.complianceLevel >= ClassFileConstants.JDK12)
+ return;
+ 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" +
+ "The preview feature Case Labels with \'->\' is only available with source level 12 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" +
+ "----------\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" +
+ "----------\n";
+
+ runComplianceParserTest(
+ testFiles,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog
+ );
+}
}
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 a12ef9f626..42fd9349dd 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
@@ -183,11 +183,16 @@ protected void verifyAllTagsCompletion() {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE
};
- } else if(this.complianceLevel > ClassFileConstants.JDK1_4) {
+ } else if(this.complianceLevel > ClassFileConstants.JDK1_4 && this.complianceLevel < ClassFileConstants.JDK12) {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
TAG_CODE, TAG_LITERAL
};
+ } else if(this.complianceLevel >= ClassFileConstants.JDK12) {
+ additionalTags = new char[][] {
+ TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
+ TAG_CODE, TAG_LITERAL, TAG_SYSTEM_PROPERTY
+ };
}
allTagsFinal = this.complianceLevel > ClassFileConstants.JDK1_8 ? allTagsJava9Plus : allTags;
if (additionalTags != null) {
@@ -279,11 +284,16 @@ public void test006() {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE
};
- } else if (this.complianceLevel > ClassFileConstants.JDK1_4) {
+ } else if(this.complianceLevel > ClassFileConstants.JDK1_4 && this.complianceLevel < ClassFileConstants.JDK12) {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
TAG_CODE, TAG_LITERAL
};
+ } else if(this.complianceLevel >= ClassFileConstants.JDK12) {
+ additionalTags = new char[][] {
+ TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
+ TAG_CODE, TAG_LITERAL, TAG_SYSTEM_PROPERTY
+ };
}
if (additionalTags != null) {
int length = allTags.length;
@@ -422,7 +432,9 @@ public void test020() {
" */\n" +
"public class Test {}\n";
verifyCompletionInJavadoc(source, "@s");
- verifyCompletionOnJavadocTag("s".toCharArray(), new char[][] { TAG_SEE, TAG_SINCE, TAG_SERIAL, TAG_SERIAL_DATA, TAG_SERIAL_FIELD }, false);
+ char[][] expectedTags = {TAG_SEE, TAG_SINCE, TAG_SERIAL, TAG_SERIAL_DATA, TAG_SERIAL_FIELD};
+ char[][] expectedTags12Plus = {TAG_SEE, TAG_SINCE, TAG_SERIAL, TAG_SERIAL_DATA, TAG_SERIAL_FIELD,TAG_SYSTEM_PROPERTY};
+ verifyCompletionOnJavadocTag("s".toCharArray(),this.complianceLevel >= ClassFileConstants.JDK12 ? expectedTags12Plus : expectedTags, false);
CompletionOnJavadocTag completionTag = (CompletionOnJavadocTag) this.javadoc.getCompletionNode();
assertEquals("Invalid tag start position", 24, completionTag.tagSourceStart);
assertEquals("Invalid tag end position", 28, completionTag.tagSourceEnd+1);
@@ -500,12 +512,16 @@ public void test025() {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE
};
- }
- else if (this.complianceLevel > ClassFileConstants.JDK1_4) {
+ }else if (this.complianceLevel > ClassFileConstants.JDK1_4 && this.complianceLevel < ClassFileConstants.JDK12) {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
TAG_CODE, TAG_LITERAL
};
+ }else if (this.complianceLevel >= ClassFileConstants.JDK12) {
+ additionalTags = new char[][] {
+ TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
+ TAG_CODE, TAG_LITERAL, TAG_SYSTEM_PROPERTY
+ };
}
if (additionalTags != null) {
int length = allTags.length;
@@ -575,12 +591,18 @@ public void test028() {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE
};
}
- else if (this.complianceLevel > ClassFileConstants.JDK1_4) {
+ else if(this.complianceLevel > ClassFileConstants.JDK1_4 && this.complianceLevel < ClassFileConstants.JDK12) {
additionalTags = new char[][] {
TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
TAG_CODE, TAG_LITERAL
};
+ } else if(this.complianceLevel >= ClassFileConstants.JDK12) {
+ additionalTags = new char[][] {
+ TAG_INHERITDOC, TAG_LINKPLAIN, TAG_VALUE,
+ TAG_CODE, TAG_LITERAL, TAG_SYSTEM_PROPERTY
+ };
}
+
if (additionalTags != null) {
int length = allTags.length;
int add = additionalTags.length;
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
new file mode 100644
index 0000000000..d8de1163d2
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest12.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 SelectionParserTest12 extends AbstractSelectionTest {
+static {
+// TESTS_NUMBERS = new int[] { 1 };
+// TESTS_NAMES = new String[] { "test005" };
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(SelectionParserTest12.class, F_12);
+}
+
+public SelectionParserTest12(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 65287abeb3..8699a67c45 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 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
@@ -153,6 +153,7 @@ public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) {
tests_10.add(CompletionParserTest18.class);
tests_10.add(SelectionParserTest18.class);
tests_10.add(SelectionParserTest9.class);
+ tests_10.add(SelectionParserTest10.class);
tests_10.add(ModuleDeclarationSyntaxTest.class);
tests_10.add(JEP286ReservedWordTest.class);
// Reset forgotten subsets tests
@@ -173,6 +174,7 @@ public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) {
tests_11.add(CompletionParserTest18.class);
tests_11.add(SelectionParserTest18.class);
tests_11.add(SelectionParserTest9.class);
+ tests_11.add(SelectionParserTest10.class);
tests_11.add(ModuleDeclarationSyntaxTest.class);
tests_11.add(JEP286ReservedWordTest.class);
// Reset forgotten subsets tests
@@ -183,6 +185,28 @@ public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) {
TestCase.RUN_ONLY_ID = null;
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11), tests_11));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_12) != 0) {
+ ArrayList tests_12 = (ArrayList)testClasses.clone();
+ tests_12.addAll(TEST_CLASSES_1_5);
+ tests_12.add(ParserTest1_7.class);
+ tests_12.add(LambdaExpressionSyntaxTest.class);
+ tests_12.add(ReferenceExpressionSyntaxTest.class);
+ tests_12.add(TypeAnnotationSyntaxTest.class);
+ tests_12.add(CompletionParserTest18.class);
+ tests_12.add(SelectionParserTest18.class);
+ tests_12.add(SelectionParserTest9.class);
+ tests_12.add(SelectionParserTest10.class);
+ tests_12.add(SelectionParserTest12.class);
+ tests_12.add(ModuleDeclarationSyntaxTest.class);
+ tests_12.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_12), tests_12));
+ }
return all;
}
public static Test suite() {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
index c0e95a3c06..83d844a35e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.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
@@ -110,6 +110,29 @@ public class AbstractComparableTest extends AbstractRegressionTest {
}
protected String intersection(String... types) {
+ // From JDK 12, Comparable gets two new super interfaces, namely Constable and ConstantDesc.
+ // The idea is to append Comparable with &Constable&ConstantDesc automatically.
+ if (isJRE12Plus) {
+ int index = -1;
+ for(int i = 0; i < types.length; i++) {
+ if (types[i].startsWith("Comparable") && !types[i].endsWith("ConstantDesc")) {
+ if ((types.length <= i+1) || !types[i+1].startsWith("CharSequence")) {
+ index = i;
+ break;
+ }
+ }
+ }
+ if (index >= 0) {
+ index++;
+ String[] temp = new String[types.length + 2];
+ System.arraycopy(types, 0, temp, 0, index);
+ temp[index] = "Constable";
+ temp[index+1] = "ConstantDesc";
+ if (index < types.length)
+ System.arraycopy(types, index, temp, index+2, types.length - index);
+ types = temp;
+ }
+ }
if (this.complianceLevel >= ClassFileConstants.JDK1_8)
return String.join(" & ", types);
return String.join("&", types);
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 bdbc45a2aa..c1f940b704 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
@@ -298,6 +298,8 @@ static class JavacCompiler {
return JavaCore.VERSION_10;
} else if(rawVersion.startsWith("11")) {
return JavaCore.VERSION_11;
+ } else if(rawVersion.startsWith("12")) {
+ return JavaCore.VERSION_12;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
@@ -408,6 +410,17 @@ static class JavacCompiler {
return 0200;
}
}
+ if (version == JavaCore.VERSION_12) {
+ if ("12".equals(rawVersion)) {
+ return 0000;
+ }
+ if ("12.0.1".equals(rawVersion)) {
+ return 0100;
+ }
+ if ("12.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
@@ -1719,6 +1732,9 @@ protected static class JavacTestOptions {
JavacTestOptions.DEFAULT /* default javac test options */);
}
protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
+ runConformTest(testFiles, expectedOutput, customOptions, null);
+ }
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments) {
runTest(
// test directory preparation
true /* flush output directory */,
@@ -1733,7 +1749,7 @@ protected static class JavacTestOptions {
null /* do not check compiler log */,
// runtime options
false /* do not force execution */,
- null /* no vm arguments */,
+ vmArguments /* no vm arguments */,
// runtime results
expectedOutput /* expected output string */,
null /* do not check error string */,
@@ -2553,10 +2569,19 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
JavacTestOptions.DEFAULT /* javac test options */);
}
protected void runNegativeTest(
+ String[] testFiles,
+ String expectedCompilerLog,
+ String[] classLibraries,
+ boolean shouldFlushOutputDirectory,
+ Map customOptions) {
+ runNegativeTest(testFiles, expectedCompilerLog, classLibraries, shouldFlushOutputDirectory, null, customOptions);
+ }
+ protected void runNegativeTest(
String[] testFiles,
String expectedCompilerLog,
String[] classLibraries,
boolean shouldFlushOutputDirectory,
+ String[] vmArguments,
Map customOptions) {
runTest(
// test directory preparation
@@ -2577,7 +2602,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
expectedCompilerLog /* expected compiler log */,
// runtime options
false /* do not force execution */,
- null /* no vm arguments */,
+ vmArguments /* no vm arguments */,
// runtime results
null /* do not check output string */,
null /* do not check error string */,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 398e5acd37..1ccbeb201b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1020,7 +1020,6 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.generateClassFiles\" value=\"enabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.maxProblemPerUnit\" value=\"100\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.APILeak\" value=\"warning\"/>\n" +
- " <option key=\"org.eclipse.jdt.core.compiler.problem.EnablePreviews\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.annotationSuperInterface\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.assertIdentifier\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.autoboxing\" value=\"ignore\"/>\n" +
@@ -1032,6 +1031,7 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.discouragedReference\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.emptyStatement\" value=\"ignore\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.enumIdentifier\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.fallthroughCase\" value=\"ignore\"/>\n" +
@@ -1091,6 +1091,7 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic\" value=\"ignore\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors\" value=\"disabled\"/>\n" +
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 4d94eadc08..04820c1a73 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2018 IBM Corporation and others.
+ * Copyright (c) 2006, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -76,270 +76,240 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
@SuppressWarnings({ "unchecked", "rawtypes" })
public class CompilerInvocationTests extends AbstractRegressionTest {
-public CompilerInvocationTests(String name) {
- super(name);
-}
+ public CompilerInvocationTests(String name) {
+ super(name);
+ }
// Static initializer to specify tests subset using TESTS_* static variables
- // All specified tests which does not belong to the class are skipped...
- // Only the highest compliance level is run; add the VM argument
- // -Dcompliance=1.4 (for example) to lower it if needed
- static {
-// TESTS_NAMES = new String[] { "test003_task_tags_options" };
+ // All specified tests which does not belong to the class are skipped...
+ // Only the highest compliance level is run; add the VM argument
+ // -Dcompliance=1.4 (for example) to lower it if needed
+ static {
+// TESTS_NAMES = new String[] { "test011_problem_categories" };
// TESTS_NUMBERS = new int[] { 1 };
// TESTS_RANGE = new int[] { 1, -1 };
// TESTS_RANGE = new int[] { 1, 2049 };
// TESTS_RANGE = new int[] { 449, 451 };
// TESTS_RANGE = new int[] { 900, 999 };
- }
+ }
-public static Test suite() {
- return buildAllCompliancesTestSuite(testClass());
-}
+ public static Test suite() {
+ return buildAllCompliancesTestSuite(testClass());
+ }
-public static Class testClass() {
- return CompilerInvocationTests.class;
-}
+ public static Class testClass() {
+ return CompilerInvocationTests.class;
+ }
// irritant vs warning token - check To/From symmetry
-public void test001_irritant_warning_token() {
- Map matcher = new HashMap();
- for (int group = 0; group < IrritantSet.GROUP_MAX; group++) {
- for (int i = 0; i < 29; i++) {
- int irritant = (group << IrritantSet.GROUP_SHIFT) + (1 << i);
- String token = CompilerOptions.warningTokenFromIrritant(irritant);
- if (token != null) {
- matcher.put(token, token);
- assertTrue(CompilerOptions.warningTokenToIrritants(token) != null);
+ public void test001_irritant_warning_token() {
+ Map matcher = new HashMap();
+ for (int group = 0; group < IrritantSet.GROUP_MAX; group++) {
+ for (int i = 0; i < 29; i++) {
+ int irritant = (group << IrritantSet.GROUP_SHIFT) + (1 << i);
+ String token = CompilerOptions.warningTokenFromIrritant(irritant);
+ if (token != null) {
+ matcher.put(token, token);
+ assertTrue(CompilerOptions.warningTokenToIrritants(token) != null);
+ }
}
}
+ // Add one for "preview", which doesn't have any irritant at the moment
+ matcher.put("preview", "preview");
+ String[] allTokens = CompilerOptions.warningTokens;
+ int length = allTokens.length;
+ matcher.put("all", "all"); // all gets undetected in the From/To loop
+ assertEquals(allTokens.length, matcher.size());
+ for (int i = 0; i < length; i++) {
+ Object object = matcher.get(allTokens[i]);
+ assertNotNull(object);
+ }
}
- // Add one for "preview", which doesn't have any irritant at the moment
- matcher.put("preview", "preview");
- String [] allTokens = CompilerOptions.warningTokens;
- int length = allTokens.length;
- matcher.put("all", "all"); // all gets undetected in the From/To loop
- assertEquals(allTokens.length, matcher.size());
- for (int i = 0; i < length; i++) {
- Object object = matcher.get(allTokens[i]);
- assertNotNull(object);
- }
-}
// problem categories - check that none is left unspecified
// see also discussion in https://bugs.eclipse.org/bugs/show_bug.cgi?id=208383
-public void test002_problem_categories() {
- try {
- Class iProblemClass;
- Field[] fields = (iProblemClass = IProblem.class).getFields();
- for (int i = 0, length = fields.length; i < length; i++) {
- Field field = fields[i];
- if (field.getType() == Integer.TYPE) {
- int problemId = field.getInt(iProblemClass), maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
- if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask
- && ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId)
- == CategorizedProblem.CAT_UNSPECIFIED) {
- fail("unspecified category for problem " + field.getName());
+ public void test002_problem_categories() {
+ try {
+ Class iProblemClass;
+ Field[] fields = (iProblemClass = IProblem.class).getFields();
+ for (int i = 0, length = fields.length; i < length; i++) {
+ Field field = fields[i];
+ if (field.getType() == Integer.TYPE) {
+ int problemId = field.getInt(iProblemClass),
+ maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
+ if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask
+ && ProblemReporter.getProblemCategory(ProblemSeverities.Error,
+ problemId) == CategorizedProblem.CAT_UNSPECIFIED) {
+ fail("unspecified category for problem " + field.getName());
+ }
}
}
+ } catch (IllegalAccessException e) {
+ fail("could not access members");
}
}
- catch (IllegalAccessException e) {
- fail("could not access members");
- }
-}
-class TasksReader implements ICompilerRequestor {
- CompilationResult result;
- public void acceptResult(CompilationResult compilationResult) {
- this.result = compilationResult;
+
+ class TasksReader implements ICompilerRequestor {
+ CompilationResult result;
+
+ public void acceptResult(CompilationResult compilationResult) {
+ this.result = compilationResult;
+ }
}
-}
-static String taskTagsAsCutAndPaste(CategorizedProblem tasks[]) {
- StringBuffer result = new StringBuffer();
- String arguments[];
- for (int i = 0; i < tasks.length - 1; i++) {
- arguments = tasks[i].getArguments();
+
+ static String taskTagsAsCutAndPaste(CategorizedProblem tasks[]) {
+ StringBuffer result = new StringBuffer();
+ String arguments[];
+ for (int i = 0; i < tasks.length - 1; i++) {
+ arguments = tasks[i].getArguments();
+ System.out.print("\t\t\"[");
+ System.out.print(arguments[0]);
+ System.out.print(',');
+ System.out.print(arguments[1]);
+ System.out.print(',');
+ System.out.print(arguments[2]);
+ System.out.println("]\\n\" +");
+ }
+ arguments = tasks[tasks.length - 1].getArguments();
System.out.print("\t\t\"[");
System.out.print(arguments[0]);
System.out.print(',');
System.out.print(arguments[1]);
System.out.print(',');
System.out.print(arguments[2]);
- System.out.println("]\\n\" +");
+ System.out.println("]\\n\"");
+ return result.toString();
}
- arguments = tasks[tasks.length - 1].getArguments();
- System.out.print("\t\t\"[");
- System.out.print(arguments[0]);
- System.out.print(',');
- System.out.print(arguments[1]);
- System.out.print(',');
- System.out.print(arguments[2]);
- System.out.println("]\\n\"");
- return result.toString();
-}
-static String taskTagsAsStrings(CategorizedProblem tasks[]) {
- StringBuffer result = new StringBuffer();
- String arguments[];
- for (int i = 0; i < tasks.length; i++) {
- arguments = tasks[i].getArguments();
- result.append('[');
- result.append(arguments[0]);
- result.append(',');
- result.append(arguments[1]);
- result.append(',');
- result.append(arguments[2]);
- result.append(']');
- result.append("\n");
- }
- return result.toString();
-}
-public void runTaskTagsOptionsTest(
- String[] testFiles,
- Map customOptions,
- String expectedTags) {
- TasksReader reader = new TasksReader();
- Map options = JavaCore.getDefaultOptions();
- if (customOptions != null) {
- options.putAll(customOptions);
+
+ static String taskTagsAsStrings(CategorizedProblem tasks[]) {
+ StringBuffer result = new StringBuffer();
+ String arguments[];
+ for (int i = 0; i < tasks.length; i++) {
+ arguments = tasks[i].getArguments();
+ result.append('[');
+ result.append(arguments[0]);
+ result.append(',');
+ result.append(arguments[1]);
+ result.append(',');
+ result.append(arguments[2]);
+ result.append(']');
+ result.append("\n");
+ }
+ return result.toString();
}
- this.runConformTest(
- testFiles,
- "",
- null /* no extra class libraries */,
- true /* flush output directory */,
- null, /* no VM args */
- options,
- reader,
- true /* skip javac */);
- String tags = taskTagsAsStrings(reader.result.tasks);
- if (! tags.equals(expectedTags)) {
- System.out.println(getClass().getName() + '#' + getName());
- System.out.println("Effective results:");
- System.out.println(tags);
- System.out.println("Cut and paste:");
- taskTagsAsCutAndPaste(reader.result.tasks);
- assertEquals(expectedTags, tags);
+
+ public void runTaskTagsOptionsTest(String[] testFiles, Map customOptions, String expectedTags) {
+ TasksReader reader = new TasksReader();
+ Map options = JavaCore.getDefaultOptions();
+ if (customOptions != null) {
+ options.putAll(customOptions);
+ }
+ this.runConformTest(testFiles, "", null /* no extra class libraries */, true /* flush output directory */,
+ null, /* no VM args */
+ options, reader, true /* skip javac */);
+ String tags = taskTagsAsStrings(reader.result.tasks);
+ if (!tags.equals(expectedTags)) {
+ System.out.println(getClass().getName() + '#' + getName());
+ System.out.println("Effective results:");
+ System.out.println(tags);
+ System.out.println("Cut and paste:");
+ taskTagsAsCutAndPaste(reader.result.tasks);
+ assertEquals(expectedTags, tags);
+ }
}
-}
+
// Basic test on task tags: watch default behavior
-public void test003_task_tags_options() {
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- null,
- "[FIXME, message contents,HIGH]\n" +
- "[TODO, message contents,NORMAL]\n" +
- "[XXX, message contents,NORMAL]\n");
-}
+ public void test003_task_tags_options() {
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ null, "[FIXME, message contents,HIGH]\n" + "[TODO, message contents,NORMAL]\n"
+ + "[XXX, message contents,NORMAL]\n");
+ }
+
// effect of cancelling priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
-public void _test004_task_tags_options() {
- Map customOptions = new HashMap();
- customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "");
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- customOptions,
- "[FIXME, message contents,NORMAL]\n" +
- "[TODO, message contents,NORMAL]\n" +
- "[XXX, message contents,NORMAL]\n");
-}
+ public void _test004_task_tags_options() {
+ Map customOptions = new HashMap();
+ customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "");
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ customOptions, "[FIXME, message contents,NORMAL]\n" + "[TODO, message contents,NORMAL]\n"
+ + "[XXX, message contents,NORMAL]\n");
+ }
+
// effect of cancelling priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
-public void _test005_task_tags_options() {
- Map customOptions = new HashMap();
- customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, ",,");
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- customOptions,
- "[FIXME,message contents,NORMAL]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
- // would expect an exception of some sort
-}
+ public void _test005_task_tags_options() {
+ Map customOptions = new HashMap();
+ customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, ",,");
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n"
+ + "[XXX,message contents,NORMAL]\n");
+ // would expect an exception of some sort
+ }
+
// effect of changing priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
-public void _test006_task_tags_options() {
- Map customOptions = new HashMap();
- customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "A,B,C,D,E");
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- customOptions,
- "[FIXME,message contents,NORMAL]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
- // would expect an exception of some sort
-}
+ public void _test006_task_tags_options() {
+ Map customOptions = new HashMap();
+ customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "A,B,C,D,E");
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n"
+ + "[XXX,message contents,NORMAL]\n");
+ // would expect an exception of some sort
+ }
+
// effect of changing priorities
-public void test007_task_tags_options() {
- Map customOptions = new HashMap();
- customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL,NORMAL");
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- customOptions,
- "[FIXME, message contents,NORMAL]\n" +
- "[TODO, message contents,NORMAL]\n" +
- "[XXX, message contents,NORMAL]\n");
-}
+ public void test007_task_tags_options() {
+ Map customOptions = new HashMap();
+ customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL,NORMAL");
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ customOptions, "[FIXME, message contents,NORMAL]\n" + "[TODO, message contents,NORMAL]\n"
+ + "[XXX, message contents,NORMAL]\n");
+ }
+
// effect of changing priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
-public void _test008_task_tags_options() {
- Map customOptions = new HashMap();
- customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL"); // one less than the number of tags
- runTaskTagsOptionsTest(
- new String[] {
- "X.java",
- "public class X {\n" +
- " void foo(X x) {\n" +
- " // FIXME TODO XXX message contents\n" +
- " }\n" +
- "}\n"},
- customOptions,
- "[FIXME,message contents,NORMAL]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
-}
+ public void _test008_task_tags_options() {
+ Map customOptions = new HashMap();
+ customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL"); // one less than the number of tags
+ runTaskTagsOptionsTest(
+ new String[] { "X.java",
+ "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n"
+ + " }\n" + "}\n" },
+ customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n"
+ + "[XXX,message contents,NORMAL]\n");
+ }
+
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206423
// that bug showed that we had no coverage in the area of missing message
// 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: 8388607. Check compiler resources.",
- new DefaultProblemFactory().getLocalizedMessage(Integer.MAX_VALUE, new String[]{}));
-}
+ public void test009_missing_message_templates() {
+ assertEquals("Unable to retrieve the error message for problem id: 4194303. Check compiler resources.",
+ new DefaultProblemFactory().getLocalizedMessage(Integer.MAX_VALUE, new String[] {}));
+ }
+
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206423
-public void test010_missing_elaboration_templates() {
- assertEquals("Unable to retrieve the error message elaboration for elaboration id: 1073741823. Check compiler resources.",
- new DefaultProblemFactory().getLocalizedMessage(0, Integer.MAX_VALUE / 2, new String[]{"Zork"}));
-}
+ public void test010_missing_elaboration_templates() {
+ assertEquals(
+ "Unable to retrieve the error message elaboration for elaboration id: 1073741823. Check compiler resources.",
+ new DefaultProblemFactory().getLocalizedMessage(0, Integer.MAX_VALUE / 2, new String[] { "Zork" }));
+ }
+
// problem categories - check that categories match expected ones
// see also discussion in https://bugs.eclipse.org/bugs/show_bug.cgi?id=208383
public void test011_problem_categories() {
@@ -1188,6 +1158,23 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("IllegalArrayOfUnionType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalArrayTypeInIntersectionCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("ProblemNotAnalysed", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
+ expectedProblemAttributes.put("SwitchExpressionsIncompatibleResultExpressionTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("SwitchExpressionsEmptySwitchBlock", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionsNoResultExpression", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("SwitchExpressionSwitchLabeledBlockCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionLastStatementCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionTrailingSwitchLabels", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("switchMixedCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionMissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionNotBelow12", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchCaseLabelWithArrowNotBelow12", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionPreviewDisabled", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchCaseLabelWithArrowPreviewDisabled", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("SwitchExpressionBreakMissingValue", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ expectedProblemAttributes.put("SwitchExpressionMissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
+ 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();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -1196,71 +1183,79 @@ public void test011_problem_categories() {
Field field1 = (Field) o1;
Field field2 = (Field) o2;
return field1.getName().compareTo(field2.getName());
- }
- });
- boolean watchInternalCategory = false, printHeader = true;
- for (int i = 0, length = fields.length; i < length; i++) {
- Field field = fields[i];
- if (field.getType() == Integer.TYPE) {
- int problemId = field.getInt(iProblemClass);
- int maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
- if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) {
- String name = field.getName();
- ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name);
- if (expectedAttributes == null) {
- failures.append("missing expected problem attributes for problem " + name + "\n");
- int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId);
- correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory) + "));\n");
- } else if (!expectedAttributes.deprecated) {
- int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId);
- correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory) + "));\n");
- if (expectedAttributes.category != actualCategory) {
- failures.append("category mismatch for problem " + name + " (expected " + categoryName(expectedAttributes.category) + ", got " + categoryName(actualCategory) + ")\n");
- }
- if (watchInternalCategory && actualCategory == CategorizedProblem.CAT_INTERNAL) {
- if (printHeader) {
- printHeader = false;
- System.err.println("CAT_INTERNAL for problems:");
+ }
+ });
+ boolean watchInternalCategory = false, printHeader = true;
+ for (int i = 0, length = fields.length; i < length; i++) {
+ Field field = fields[i];
+ if (field.getType() == Integer.TYPE) {
+ int problemId = field.getInt(iProblemClass);
+ int maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
+ if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) {
+ String name = field.getName();
+ ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name);
+ if (expectedAttributes == null) {
+ failures.append("missing expected problem attributes for problem " + name + "\n");
+ int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId);
+ correctResult.append("\t\texpectedProblemAttributes.put(\"" + name
+ + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory)
+ + "));\n");
+ } else if (!expectedAttributes.deprecated) {
+ int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId);
+ correctResult.append("\t\texpectedProblemAttributes.put(\"" + name
+ + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory)
+ + "));\n");
+ if (expectedAttributes.category != actualCategory) {
+ failures.append("category mismatch for problem " + name + " (expected "
+ + categoryName(expectedAttributes.category) + ", got "
+ + categoryName(actualCategory) + ")\n");
+ }
+ if (watchInternalCategory && actualCategory == CategorizedProblem.CAT_INTERNAL) {
+ if (printHeader) {
+ printHeader = false;
+ System.err.println("CAT_INTERNAL for problems:");
+ }
+ System.err.println("\t" + name);
}
- System.err.println("\t" + name);
+ } else {
+ correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", DEPRECATED);\n");
}
- } else {
- correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", DEPRECATED);\n");
}
}
}
+ if (failures.length() > 0) {
+ System.out.println(correctResult);
+ System.out.println();
+ }
+ assertEquals(failures.toString(), 0, failures.length());
+ } catch (IllegalAccessException e) {
+ fail("could not access members");
}
- if (failures.length() > 0) {
- System.out.println(correctResult);
- System.out.println();
- }
- assertEquals(failures.toString(), 0, failures.length());
- }
- catch (IllegalAccessException e) {
- fail("could not access members");
}
-}
-private static Map categoryNames;
-private String categoryName(int category) {
- if (categoryNames == null) {
- categoryNames = new HashMap();
- Field[] fields = CategorizedProblem.class.getFields();
- for (int i = 0, length = fields.length; i < length; i++) {
- Field field = fields[i];
- if (field.getType() == Integer.TYPE) {
- String name = field.getName();
- if (name.startsWith("CAT_")) {
- try {
- categoryNames.put(Integer.valueOf(field.getInt(CategorizedProblem.class)), name);
- } catch (IllegalArgumentException e) {
- } catch (IllegalAccessException e) {
+
+ private static Map categoryNames;
+
+ private String categoryName(int category) {
+ if (categoryNames == null) {
+ categoryNames = new HashMap();
+ Field[] fields = CategorizedProblem.class.getFields();
+ for (int i = 0, length = fields.length; i < length; i++) {
+ Field field = fields[i];
+ if (field.getType() == Integer.TYPE) {
+ String name = field.getName();
+ if (name.startsWith("CAT_")) {
+ try {
+ categoryNames.put(Integer.valueOf(field.getInt(CategorizedProblem.class)), name);
+ } catch (IllegalArgumentException e) {
+ } catch (IllegalAccessException e) {
+ }
}
}
}
}
+ return (String) categoryNames.get(Integer.valueOf(category));
}
- return (String) categoryNames.get(Integer.valueOf(category));
-}
+
// compiler problems tuning
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=218603
public void test012_compiler_problems_tuning() {
@@ -2108,6 +2103,23 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("VarLocalReferencesItself", SKIP);
expectedProblemAttributes.put("VarLocalTooManyBrackets", SKIP);
expectedProblemAttributes.put("VarLocalWithoutInitizalier", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsIncompatibleResultExpressionTypes",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsEmptySwitchBlock",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionsNoResultExpression",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionSwitchLabeledBlockCompletesNormally",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionLastStatementCompletesNormally",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionTrailingSwitchLabels",SKIP);
+ expectedProblemAttributes.put("switchMixedCase", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionMissingDefaultCase",SKIP);
+ expectedProblemAttributes.put("SwitchExpressionNotBelow12", SKIP);
+ expectedProblemAttributes.put("SwitchCaseLabelWithArrowNotBelow12", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionPreviewDisabled", SKIP);
+ expectedProblemAttributes.put("SwitchCaseLabelWithArrowPreviewDisabled", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionBreakMissingValue", SKIP);
+ expectedProblemAttributes.put("SwitchExpressionMissingEnumConstantCase", SKIP);
+ expectedProblemAttributes.put("PreviewFeatureDisabled", SKIP);
+ expectedProblemAttributes.put("PreviewFeatureUsed", SKIP);
+ expectedProblemAttributes.put("PreviewFeatureNotSupported", SKIP);
Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
@@ -2115,46 +2127,47 @@ public void test012_compiler_problems_tuning() {
String fieldName;
if (field.getType() == String.class && (fieldName = field.getName()).startsWith("COMPILER_PB_")) {
constantNamesIndex.put(field.get(null), fieldName);
+ }
}
- }
- fields = IProblem.class.getFields();
- StringBuffer failures = new StringBuffer();
- StringBuffer correctResult = new StringBuffer(70000);
- Arrays.sort(fields, new Comparator() {
- public int compare(Object o1, Object o2) {
- Field field1 = (Field) o1;
- Field field2 = (Field) o2;
- return field1.getName().compareTo(field2.getName());
- }
- });
- for (int i = 0, length = fields.length; i < length; i++) {
- Field field = fields[i];
- if (field.getType() == Integer.TYPE) {
- int problemId = field.getInt(null), maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
- if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) {
- String name = field.getName();
- ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name);
- String actualTuningOption = JavaCore.getOptionForConfigurableSeverity(problemId);
- if (expectedAttributes == null) {
- failures.append("missing expected problem attributes for problem " + name + "\n");
- } else if (!expectedAttributes.skip && !expectedAttributes.option.equals(actualTuningOption)) {
- failures.append("tuning option mismatch for problem " + name + " (expected " + expectedAttributes.option + ", got " + actualTuningOption + ")\n");
+ fields = IProblem.class.getFields();
+ StringBuffer failures = new StringBuffer();
+ StringBuffer correctResult = new StringBuffer(70000);
+ Arrays.sort(fields, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Field field1 = (Field) o1;
+ Field field2 = (Field) o2;
+ return field1.getName().compareTo(field2.getName());
+ }
+ });
+ for (int i = 0, length = fields.length; i < length; i++) {
+ Field field = fields[i];
+ if (field.getType() == Integer.TYPE) {
+ int problemId = field.getInt(null), maskedProblemId = problemId & IProblem.IgnoreCategoriesMask;
+ if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) {
+ String name = field.getName();
+ ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name);
+ String actualTuningOption = JavaCore.getOptionForConfigurableSeverity(problemId);
+ if (expectedAttributes == null) {
+ failures.append("missing expected problem attributes for problem " + name + "\n");
+ } else if (!expectedAttributes.skip && !expectedAttributes.option.equals(actualTuningOption)) {
+ failures.append("tuning option mismatch for problem " + name + " (expected "
+ + expectedAttributes.option + ", got " + actualTuningOption + ")\n");
+ }
+ String optionFieldName = (String) constantNamesIndex.get(actualTuningOption);
+ correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", "
+ + (optionFieldName != null ? "new ProblemAttributes(JavaCore." + optionFieldName + ")"
+ : "SKIP")
+ + ");\n");
}
- String optionFieldName = (String) constantNamesIndex.get(actualTuningOption);
- correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", " +
- (optionFieldName != null ? "new ProblemAttributes(JavaCore." + optionFieldName + ")" :
- "SKIP") + ");\n");
}
}
+ if (failures.length() > 0) {
+ System.out.println(correctResult);
+ System.out.println();
+ }
+ assertEquals(failures.toString(), 0, failures.length());
+ } catch (IllegalAccessException e) {
+ fail("could not access members");
}
- if (failures.length() > 0) {
- System.out.println(correctResult);
- System.out.println();
- }
- assertEquals(failures.toString(), 0, failures.length());
- }
- catch (IllegalAccessException e) {
- fail("could not access members");
}
}
-}
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 5602566218..b0514b8936 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2018 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
@@ -2904,6 +2904,1944 @@ public void testBug537804_comment5() {
"The local variable action may not have been initialized\n" +
"----------\n");
}
+public void testBug542707_001() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_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" +
+ " ^\n" +
+ "The local variable k may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 14)\n" +
+ " return k + it;\n" +
+ " ^\n" +
+ "The local variable k may not have been initialized\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " final int k;\n" +
+ "\n" +
+ " int it = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " k = 1;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " break k;\n" +
+ " }\n" +
+ " };\n" +
+ " return k + it;\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+
+}
+public void testBug542707_002() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " k = switch (i) { \n" +
+ " ^\n" +
+ "The final local variable k may already have been assigned\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " break k;\n" +
+ " ^\n" +
+ "The local variable k may not have been initialized\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " final int k;\n" +
+ "\n" +
+ " k = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " k = 1;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " default -> {\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
+/*
+ * k is definitely assigned - no errors on that front.
+ */
+public void testBug542707_003() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 23)\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" +
+ " final int k;\n" +
+ "\n" +
+ " int it = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " k = 1;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " case 2 -> {\n" +
+ " k = 2;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " k = 3;\n" +
+ " break k;\n" +
+ " }\n" +
+ " };\n" +
+ " return k;\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);
+}
+public void testBug542707_004() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " k = 1;\n" +
+ " ^\n" +
+ "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " k = 2;\n" +
+ " ^\n" +
+ "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 15)\n" +
+ " k = 3;\n" +
+ " ^\n" +
+ "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 23)\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" +
+ " final int k = 1;\n" +
+ "\n" +
+ " int it = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " k = 1;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " case 2 -> {\n" +
+ " k = 2;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " k = 3;\n" +
+ " break k;\n" +
+ " }\n" +
+ " };\n" +
+ " return k;\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);
+}
+public void testBug542707_005() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_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" +
+ " ^\n" +
+ "The local variable k may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 18)\n" +
+ " return k;\n" +
+ " ^\n" +
+ "The local variable k may not have been initialized\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 22)\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" +
+ " final int k;\n" +
+ "\n" +
+ " int it = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " k = 1;\n" +
+ " break k ;\n" +
+ " }\n" +
+ " case 2 -> {\n" +
+ " break k ;\n" +
+ " }\n" +
+ " default -> {\n" +
+ " k = 3;\n" +
+ " break k;\n" +
+ " }\n" +
+ " };\n" +
+ " return k;\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 12 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
+ * 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
+ * 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 22)\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 :\n" +
+ " v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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
+ * 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
+ * statement and V is definitely unassigned after e when false.
+ */
+public void testBug542707_007() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 18)\n" +
+ " return v + d;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 22)\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 :\n" +
+ " //v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " //v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " //v = 3;\n" +
+ " break 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 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 22)\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 = 1;\n" +
+ " boolean b = switch (i) {\n" +
+ " case 1 :\n" +
+ " //v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " //v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " //v = 3;\n" +
+ " break 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 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " boolean b = switch (v) {\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 22)\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 (v) {\n" +
+ " case 1 :\n" +
+ " v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 22)\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 + (v =1)) {\n" +
+ " case 1 :\n" +
+ " v += 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " v += 1;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 22)\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 :\n" +
+ " v += 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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
+ */
+public void testBug542707_012() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 22)\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 + (v =1)) {\n" +
+ " case 1 :\n" +
+ " v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v += 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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
+ */
+public void testBug542707_013() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " v += 2;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 22)\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 :\n" +
+ " v = 1;\n" +
+ " break true;\n" +
+ " case 2 : {\n" +
+ " v += 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " default : {\n" +
+ " v = 3;\n" +
+ " break 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 12 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,
+ * 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,
+ * V is definitely assigned after e when false.
+ * It is a switch labeled throw statement.
+ */
+public void testBug542707_014() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 23)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v;\n" +
+ " boolean b = switch (i ) {\n" +
+ " case 0 -> (v = 1) != 0;\n" +
+ " case 1 -> (v = 1) == 0;\n" +
+ " case 2 -> {\n" +
+ " v = 2;\n" +
+ " break true;\n" +
+ " }\n" +
+ " case 3 -> {\n" +
+ " v = 3;\n" +
+ " break false;\n" +
+ " }\n" +
+ " default -> throw new IOException();\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" +
+ " try {\n" +
+ " System.out.println(foo(3));\n" +
+ " } catch (IOException e) {\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
+/**
+ * From JLS 12 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
+ * 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
+ * after e when false.
+ * It is a switch labeled throw statement.
+ */
+public void testBug542707_015() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 17)\n" +
+ " return v + d;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 21)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v;\n" +
+ " boolean b = switch (i ) {\n" +
+ " case 0 -> true;\n" +
+ " case 1 -> false;\n" +
+ " case 2 -> {\n" +
+ " break true;\n" +
+ " }\n" +
+ " case 3 -> {\n" +
+ " break false;\n" +
+ " }\n" +
+ " default -> throw new IOException();\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" +
+ " try {\n" +
+ " System.out.println(foo(3));\n" +
+ " } catch (IOException e) {\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
+/**
+ * From JLS 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 14)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v;\n" +
+ " boolean b = switch ((v = 1)) {\n" +
+ " case 0 -> v != 0;\n" +
+ " default -> throw new IOException();\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" +
+ " try {\n" +
+ " System.out.println(foo(3));\n" +
+ " } catch (IOException e) {\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
+/**
+ * From JLS 12 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)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " case 0 -> v != 0;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " return v + d;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 14)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v;\n" +
+ " boolean b = switch (i) {\n" +
+ " case 0 -> v != 0;\n" +
+ " default -> throw new IOException();\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" +
+ " try {\n" +
+ " System.out.println(foo(3));\n" +
+ " } catch (IOException e) {\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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.
+ */
+public void testBug542707_018() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 20)\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" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " v = 1; // definitely assigned before break\n" +
+ " break v;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break v =1; // definitely assigned after e\n" +
+ " }\n" +
+ " default : {\n" +
+ " break v = 2;\n" +
+ " }\n" +
+ " };\n" +
+ " return v + t;\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 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.
+ */
+public void testBug542707_019() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 15)\n" +
+ " return v + t;\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" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " break 1;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return v + t;\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 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 [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
+ */
+public void testBug542707_020() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. 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 =1;\n" +
+ " int t = switch (v) {\n" +
+ " case 0 : {\n" +
+ " break 1;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return t;\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 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 [un]assigned before the selector expression iff V is [un]assigned before the switch statement.
+ */
+public void testBug542707_021() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " int t = switch (v) {\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" +
+ " int t = switch (v) {\n" +
+ " case 0 : {\n" +
+ " break 1;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return t;\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 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 [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_022() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. 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 =1;\n" +
+ " int t = switch (v) {\n" +
+ " case 0 : {\n" +
+ " break v;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return t;\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 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 [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_023() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_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" +
+ " ^\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" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " break v;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return t;\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 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 [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.
+ */
+public void testBug542707_024() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_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" +
+ " ^\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" +
+ " int t = switch (i) {\n" +
+ " case 0 : {\n" +
+ " break 1;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break v;\n" +
+ " }\n" +
+ " default : {\n" +
+ " break 3;\n" +
+ " }\n" +
+ " };\n" +
+ " return t;\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 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.
+ */
+public void testBug542707_025() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 20)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " int t = switch (i) {\n" +
+ " case 0 -> v = 1;\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " break v = 2;\n" +
+ " }\n" +
+ " break v = 3;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return v + t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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.
+ */
+public void testBug542707_026() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 16)\n" +
+ " return v + t;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 20)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " int t = switch (i) {\n" +
+ " case 0 -> 1;\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " break 3;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return v + t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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 [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_027() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 20)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " int t = switch (v = 1) {\n" +
+ " case 0 -> v;\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " break 3;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return v + t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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 [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_028() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " case 0 -> v;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 20)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " int t = switch (i) {\n" +
+ " case 0 -> v;\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " break 2;\n" +
+ " }\n" +
+ " break 3;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return t;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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.
+ */
+public void testBug542707_029() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "2. ERROR in X.java (at line 24)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " switch (i) {\n" +
+ " case 0 -> {\n" +
+ " v = 0;\n" +
+ " }\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " v = 2;\n" +
+ " break;\n" +
+ " }\n" +
+ " v = 3;\n" +
+ " break;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return v;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ 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.
+ */
+public void testBug542707_030() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ 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_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 20)\n" +
+ " return v;\n" +
+ " ^\n" +
+ "The local variable v may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 24)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n";
+ String[] testFiles = new String[] {
+ "X.java", // =================
+ "import java.io.IOException;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static int foo(int i) throws IOException {\n" +
+ " int v ;\n" +
+ " switch (i) {\n" +
+ " case 0 -> {\n" +
+ " v = 0;\n" +
+ " }\n" +
+ " case 2 -> {\n" +
+ " if (i > 1) {\n" +
+ " v = 2;\n" +
+ " break;\n" +
+ " }\n" +
+ " // v = 3;\n" +
+ " break;\n" +
+ " }\n" +
+ " default -> throw new IOException();\n" +
+ " };\n" +
+ " return v;\n" +
+ " }\n" +
+ " \n" +
+ " public boolean bar() {\n" +
+ " Zork();\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",
+ };
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ defaultOptions);
+}
public static Class testClass() {
return FlowAnalysisTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 10d7a54ce5..de0df414ab 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -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
@@ -15337,7 +15337,9 @@ public void test0499(){
"1. ERROR in X.java (at line 6)\n" +
" Integer[] var = cond ? tab1 : tab2;\n" +
" ^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from Object&Serializable&Comparable<? extends Object&Serializable&Comparable<?>>[] to Integer[]\n" +
+ "Type mismatch: cannot convert from Object&Serializable&" +
+ "" + intersection("Comparable<? extends Object&Serializable&" + intersection("Comparable<?>") + ">") +
+ "[] to Integer[]\n" +
"----------\n":
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
@@ -19815,7 +19817,7 @@ public void test0617() {
"1. ERROR in X.java (at line 10)\n" +
" String s = l1 != null ? foo(l1, l2) : l3;\n" +
" ^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from List<capture#2-of ? extends Number & Comparable<?>> to String\n" +
+ "Type mismatch: cannot convert from List<capture#2-of ? extends Number & "+intersection("Comparable<?>")+"> to String\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=92556
@@ -25439,7 +25441,7 @@ public void test0790() {
"1. ERROR in X.java (at line 7)\n" +
" if (isGreater(i, d)) \n" +
" ^^^^^^^^^\n" +
- "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Integer, Double). The inferred type Number&Comparable<?> is not a valid substitute for the bounded parameter <T extends Comparable<T>>\n" +
+ "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Integer, Double). The inferred type "+ intersection("Number", "Comparable<?>") +" is not a valid substitute for the bounded parameter <T extends Comparable<T>>\n" +
"----------\n" +
"2. ERROR in X.java (at line 15)\n" +
" isGreater(c1, c2);\n" +
@@ -26064,7 +26066,9 @@ public void test0805() {
"2. ERROR in X.java (at line 14)\n" +
" String s2 = foo(integers, floats);\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from "+intersection("Number","Comparable<? extends "+intersection("Number","Comparable<?>")+">[]")+" to String\n" +
+ "Type mismatch: cannot convert from "+intersection("Number",
+ intersection("Comparable<? extends "+intersection("Number","Comparable<?>")+">")
+ )+"[] to String\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107079
@@ -33564,12 +33568,12 @@ public void test1000() {
"4. WARNING in X.java (at line 14)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type safety: A generic array of Iterator<? extends Number&Comparable<?>> is created for a varargs parameter\n" +
+ "Type safety: A generic array of Iterator<? extends "+ intersection("Number", "Comparable<?>") +"> is created for a varargs parameter\n" +
"----------\n" +
"5. ERROR in X.java (at line 14)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from Iterator<Number&Comparable<?>> to Iterator<Number>\n" +
+ "Type mismatch: cannot convert from Iterator<"+ intersection("Number", "Comparable<?>") +"> to Iterator<Number>\n" +
"----------\n" +
"6. WARNING in X.java (at line 18)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" +
@@ -33606,12 +33610,12 @@ public void test1000() {
"5. WARNING in X.java (at line 14)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type safety: A generic array of Iterator<? extends Number&Comparable<?>> is created for a varargs parameter\n" +
+ "Type safety: A generic array of Iterator<? extends Number&"+ intersection("Comparable<?>") +"> is created for a varargs parameter\n" +
"----------\n" +
"6. ERROR in X.java (at line 14)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from Iterator<Number&Comparable<?>> to Iterator<Number>\n" +
+ "Type mismatch: cannot convert from Iterator<Number&"+ intersection("Comparable<?>") +"> to Iterator<Number>\n" +
"----------\n" +
"7. WARNING in X.java (at line 18)\n" +
" Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" +
@@ -34746,7 +34750,7 @@ public void test1029() {
"1. ERROR in X.java (at line 10)\n" +
" List<Number> name = makeNumberList(5, 5D);\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from List<Number&Comparable<?>> to List<Number>\n" +
+ "Type mismatch: cannot convert from List<"+ intersection("Number", "Comparable<?>") +"> to List<Number>\n" +
"----------\n",
null,
true,
@@ -39658,7 +39662,7 @@ public void test1136() {
"1. ERROR in X.java (at line 4)\n" +
" List<Object> l1 = Arrays.asList(1, \"X\");\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from List<Object&Comparable<?>&Serializable> to List<Object>\n" +
+ "Type mismatch: cannot convert from List<Object&"+ intersection("Comparable<?>") +"&Serializable> to List<Object>\n" +
"----------\n" +
"2. ERROR in X.java (at line 8)\n" +
" List<Object> l2 = Arrays.asList(b, c);\n" +
@@ -43202,7 +43206,7 @@ public void test1227() {
"1. WARNING in X.java (at line 4)\n" +
" Arrays.asList(String.class, Integer.class);\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type safety: A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" +
+ "Type safety: A generic array of Class<? extends Object&Serializable&"+ intersection("Comparable<?>") +"> is created for a varargs parameter\n" +
"----------\n" +
"2. ERROR in X.java (at line 6)\n" +
" Zork z;\n" +
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 d7c3fb22de..4d1d261c6b 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 Jesper Steen Møller and others.
+ * Copyright (c) 2018, 2019 Jesper Steen Møller and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -69,7 +69,11 @@ static {
simpleTypeNames.put("ComparableAny", "Comparable<?>");
simpleTypeNames.put("CollectionExt_ComparableAny", "Collection<? extends Comparable<?>>");
simpleTypeNames.put("CollectionSuperComparableAny", "Collection<? super Comparable<?>>");
- simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable<?>");
+ isJRE12Plus = isJRELevel(F_12);
+ if (isJRE12Plus)
+ simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable<?> & java.lang.constant.Constable & java.lang.constant.ConstantDesc");
+ else
+ simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable<?>");
simpleTypeNames.put("ListTestAndSerializable", "List<? extends Z & java.io.Serializable>");
simpleTypeNames.put("TestAndSerializable", "Z & java.io.Serializable");
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index 349e89cf8d..bdbb120e13 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -4325,6 +4325,121 @@ public void testBug521362_emptyFile() {
true,
/*not tested with javac*/"");
}
+ public void testReleaseOption20() throws Exception {
+ if (!isJRE12Plus) return;
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String str = Integer.toUnsignedString(1, 1);\n" +
+ " }\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " --release 7 -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
+ " String str = Integer.toUnsignedString(1, 1);\n" +
+ " ^^^^^^^^^^^^^^^^\n" +
+ "The method toUnsignedString(int, int) is undefined for the type Integer\n" +
+ "----------\n" +
+ "1 problem (1 error)\n",
+ true);
+ }
+ public void testReleaseOption21() throws Exception {
+ if (!isJRE12Plus) return;
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " Integer.toUnsignedString(1, 1);\n" +
+ " }\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " --release 8 -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "",
+ true);
+ }
+ public void testReleaseOption22() {
+ if (isJRE11Plus || isJRE12Plus) return;
+ runConformTest(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ "}",
+ "module-info.java",
+ "module mod.one { \n" +
+ " requires java.base;\n" +
+ " requires java.xml.ws.annotation;\n" +
+ "}"
+ },
+ " --limit-modules java.base,java.xml.ws.annotation " +
+ " --release 10 \"" + OUTPUT_DIR + File.separator + "module-info.java\" "
+ + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/module-info.java (at line 3)\n" +
+ " requires java.xml.ws.annotation;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The module java.xml.ws.annotation has been deprecated since version 9 and marked for removal\n" +
+ "----------\n" +
+ "1 problem (1 warning)\n",
+ true);
+ }
+ public void testReleaseOption23() {
+ if (!isJRE11Plus) return;
+ runNegativeTest(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ "}",
+ "module-info.java",
+ "module mod.one { \n" +
+ " requires java.xml.ws.annotation;\n" +
+ "}"
+ },
+ " --limit-modules java.base,java.xml.ws.annotation " +
+ " --release 11 \"" + OUTPUT_DIR + File.separator + "module-info.java\" "
+ + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"",
+ "",
+ "invalid module name: java.xml.ws.annotation\n",
+ true);
+ }
+ public void testReleaseOption24() {
+ if (!isJRE11Plus) return;
+ runNegativeTest(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " }\n" +
+ "}",
+ "module-info.java",
+ "module mod.one { \n" +
+ " requires java.xml.ws.annotation;\n" +
+ "}"
+ },
+ " --limit-modules java.base,java.xml.ws.annotation " +
+ " --release 12 \"" + OUTPUT_DIR + File.separator + "module-info.java\" "
+ + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"",
+ "",
+ "invalid module name: java.xml.ws.annotation\n",
+ true);
+ }
public void testLimitModules1() {
File outputDirectory = new File(OUTPUT_DIR);
Util.flushDirectoryContent(outputDirectory);
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 57ce8de4d6..63fa7e928d 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2018 GK Software AG and others.
+ * Copyright (c) 2010, 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
@@ -10359,4 +10359,228 @@ public void testBug530970_on_field_bin() {
"----------\n"
);
}
+public void testBug542707_001() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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 15)\n" +
+ " default -> null;\n" +
+ " ^^^^\n" +
+ "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" +
+ "----------\n"
+ );
+}
+/**
+ * should not throw IOOBE while building - a safety check test case.
+ */
+public void testBug542707_002() {
+ if (this.complianceLevel != ClassFileConstants.JDK12)
+ return;
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ 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 13)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n"
+ );
+}
+public void testBug542707_003() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ // outer expected type (from assignment) is propagated deeply into a switch expression
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runner.classLibraries = this.LIBS;
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable String maybe() { return null; }\n" +
+ " void test(int i) {\n" +
+ " @NonNull String s = switch (i) {\n" +
+ " case 1 -> \"\";\n" +
+ " default -> i == 3 ? maybe() : \"\";\n" +
+ " };\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\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" +
+ "----------\n";
+ runner.runNegativeTest();
+}
+// failing, see https://bugs.eclipse.org/543860
+public void _testBug542707_004() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ // outer expected type (from method parameter) is propagated deeply into a switch expression
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runner.classLibraries = this.LIBS;
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable String maybe() { return null; }\n" +
+ " void need(@NonNull String s) {\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " }\n" +
+ " void test(int i) {\n" +
+ " need(switch (i) {\n" +
+ " case 1 -> \"\";\n" +
+ " default -> i == 3 ? maybe() : \"\";\n" +
+ " });\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " default -> i == 3 ? maybe() : \"\";\n" +
+ " ^^^^^^^\n" +
+ "Null type mismatch (type annotations): required '@NonNull String' but this expression has type '@Nullable String'\n" +
+ "----------\n";
+ runner.runNegativeTest();
+}
+public void testBug542707_005() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ // switch value must not be null (@Nullable)
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runner.classLibraries = this.LIBS;
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "enum SomeDays { Mon, Wed, Fri }\n" +
+ "public class X {\n" +
+ " int testEnum(@Nullable SomeDays day) {\n" +
+ " return switch(day) {\n" +
+ " case Mon -> 1;\n" +
+ " case Wed -> 2;\n" +
+ " case Fri -> 3;\n" +
+ " };\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\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";
+ runner.runNegativeTest();
+}
+public void testBug542707_006() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ // switch value must not be null (pot-null by flow analysis)
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runner.classLibraries = this.LIBS;
+ runner.testFiles = new String[] {
+ "X.java",
+ "enum SomeDays { Mon, Wed, Fri }\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"
+ };
+ runner.expectedCompilerLog =
+ "----------\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";
+ runner.runNegativeTest();
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index 60f05cc089..8649fd72dd 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 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
@@ -45,6 +45,7 @@
package org.eclipse.jdt.core.tests.compiler.regression;
import java.io.File;
+import java.util.HashMap;
import java.util.Map;
import junit.framework.Test;
@@ -18237,4 +18238,31 @@ public void testBug536408() {
runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError;
runner.runNegativeTest();
}
+public void testBug542707_1() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ Runner runner = new Runner();
+ runner.customOptions = new HashMap<>();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ runner.testFiles = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void test(int i) {\n" +
+ " String s = switch (i) {\n" +
+ " case 1 -> \"one\";\n" +
+ " default -> null;\n" +
+ " };\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " System.out.println(s.toLowerCase());\n" +
+ " ^\n" +
+ "Potential null pointer access: The variable s may be null at this location\n" +
+ "----------\n";
+ runner.runNegativeTest();
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index ccbd91de8a..757f3f4bbd 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2018 GK Software AG and others.
+ * Copyright (c) 2012, 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
@@ -17749,4 +17749,52 @@ public void testBug540264() {
"----------\n"
);
}
+public void testBug542707_1() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression
+ // switch expression has a functional type with interesting type inference and various null issues:
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ runner.customOptions.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ runner.classLibraries = this.LIBS;
+ runner.testFiles = new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {}\n" +
+ "interface IN1 extends IN0 {}\n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n1() { return new IN1() {}; }\n" +
+ " IN2 n2() { return null; }\n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { }\n" +
+ " void testSw(int i) {\n" +
+ " m(switch(i) {\n" +
+ " case 1 -> this::n1;\n" +
+ " case 2 -> () -> n1();\n" +
+ " case 3 -> null;\n" +
+ " case 4 -> () -> n2();\n" +
+ " default -> this::n2; });\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.expectedCompilerLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 14)\n" +
+ " case 3 -> null;\n" +
+ " ^^^^\n" +
+ "Null type mismatch: required \'@NonNull Supplier<@NonNull IN0>\' but the provided value is null\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 15)\n" +
+ " case 4 -> () -> n2();\n" +
+ " ^^^^\n" +
+ "Null type safety (type annotations): The expression of type \'IN2\' needs unchecked conversion to conform to \'@NonNull IN0\'\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 16)\n" +
+ " default -> this::n2; });\n" +
+ " ^^^^^^^^\n" +
+ "Null type safety at method return type: Method descriptor Supplier<IN0>.get() promises \'@NonNull IN0\' but referenced method provides \'IN2\'\n" +
+ "----------\n";
+ runner.runNegativeTest();
+}
}
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 0d2d7a5b82..76b77b3bca 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 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
@@ -53,7 +53,7 @@ private static final String APACHE_DBUTILS_CONTENT = "package org.apache.commons
"}\n";
static {
-// TESTS_NAMES = new String[] { "testBug462371_shouldWarn" };
+// TESTS_NAMES = new String[] { "testBug542707" };
// TESTS_NUMBERS = new int[] { 50 };
// TESTS_RANGE = new int[] { 11, -1 };
}
@@ -5496,4 +5496,176 @@ public void testBug541705b() {
};
runner.runConformTest();
}
+public void testBug542707_001() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) 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);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runLeakTest(
+ new String[] {
+ "X.java",
+ "import java.io.Closeable;\n"+
+ "import java.io.IOException;\n"+
+ "\n"+
+ "public class X implements Closeable{\n"+
+ " public static int foo(int i) throws IOException {\n"+
+ " int k = 0;\n"+
+ " X x = null;\n"+
+ " try {\n"+
+ " x = new X();\n"+
+ " x = switch (i) { \n"+
+ " case 1 -> {\n"+
+ " break x;\n"+
+ " }\n"+
+ " default -> x;\n"+
+ " };\n"+
+ " } finally {\n"+
+ " x.close();\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"+
+ " @Override\n"+
+ " public void close() throws IOException {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 31)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n",
+ options);
+}
+public void testBug542707_002() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) 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);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runLeakTest(
+ new String[] {
+ "X.java",
+ "import java.io.Closeable;\n"+
+ "import java.io.IOException;\n"+
+ "\n"+
+ "public class X implements Closeable{\n"+
+ " public static int foo(int i) throws IOException {\n"+
+ " int k = 0;\n"+
+ " X x = null;\n"+
+ " try {\n"+
+ " x = new X();\n"+
+ " x = switch (i) { \n"+
+ " case 1 -> {\n"+
+ " x = new X();\n"+
+ " break x;\n"+
+ " }\n"+
+ " default -> x;\n"+
+ " };\n"+
+ " } finally {\n"+
+ " x.close();\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"+
+ " @Override\n"+
+ " public void close() throws IOException {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " x = new X();\n" +
+ " ^^^^^^^^^^^\n" +
+ "Resource leak: \'x\' is not closed at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 32)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n",
+ options);
+}
+public void testBug542707_003() {
+ if (this.complianceLevel < ClassFileConstants.JDK12) 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);
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ runLeakTest(
+ new String[] {
+ "X.java",
+ "import java.io.Closeable;\n"+
+ "import java.io.IOException;\n"+
+ "\n"+
+ "public class X implements Closeable{\n"+
+ " public static int foo(int i) throws IOException {\n"+
+ " int k = 0;\n"+
+ " X x = null;\n"+
+ " try {\n"+
+ " x = new X();\n"+
+ " x = switch (i) { \n"+
+ " case 1 -> {\n"+
+ " break new X();\n"+
+ " }\n"+
+ " default -> x;\n"+
+ " };\n"+
+ " } finally {\n"+
+ " x.close();\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"+
+ " @Override\n"+
+ " public void close() throws IOException {\n"+
+ " Zork();\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " x = switch (i) { \n" +
+ " case 1 -> {\n" +
+ " break new X();\n" +
+ " }\n" +
+ " default -> x;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Resource leak: \'x\' is not closed at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 31)\n" +
+ " Zork();\n" +
+ " ^^^^\n" +
+ "The method Zork() is undefined for the type X\n" +
+ "----------\n",
+ options);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
new file mode 100644
index 0000000000..78b120276e
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -0,0 +1,2365 @@
+/*******************************************************************************
+ * Copyright (c) 2018, 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.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+import junit.framework.Test;
+
+public class SwitchExpressionTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+// TESTS_NAMES = new String[] { "testBug543240_1" };
+ }
+
+ public static Class<?> testClass() {
+ return SwitchExpressionTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_12);
+ }
+ public SwitchExpressionTest(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_12); // FIXME
+ defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
+ defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ return defaultOptions;
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, Map customOptions) {
+ super.runConformTest(testFiles, "", null, true, new String[] {"--enable-preview"}, customOptions, null);
+ }
+
+ @Override
+ protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) {
+ super.runConformTest(testFiles, expectedOutput, null, true, new String[] {"--enable-preview"}, customOptions, null);
+ }
+ public void testSimpleExpressions() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testSwitchExpression_531714_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"+
+ " break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug531714_error_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 testBug531714_error_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" +
+ " break 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 testBug531714_error_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" +
+ " break 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 _testBug531714_error_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" +
+ " break 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 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug531714_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 testBug543667_001() {
+ 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",
+ null,
+ false,
+ new String[] { "--enable-preview"});
+ }
+ public void testBug531714_009() {
+ 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 testBug531714_010() {
+ 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 testBug531714_011() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ 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,
+ null,
+ true,
+ getCompilerOptions());
+ }
+ public void testBug531714_012() {
+ 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 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" +
+ "----------\n";
+ this.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ options);
+ } finally {
+ options.put(CompilerOptions.OPTION_Source, release);
+ }
+ }
+ public void testBug531714_013() {
+ 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" +
+ " break 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,
+ null,
+ true,
+ getCompilerOptions());
+ }
+ public void testBug531714_014() {
+ // 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 testBug543673_001() {
+ 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",
+ null,
+ false,
+ new String[] { "--enable-preview"});
+ }
+ /*
+ * A simple multi constant case statement, compiled and run as expected
+ */
+ public void testBug543240_1() {
+ 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 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,
+ options,
+ new String[] { "--enable-preview"});
+ }
+ /*
+ * A simple multi constant case statement, compiler reports missing enum constants
+ */
+ public void testBug543240_1a() {
+ 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(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.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ /*
+ * A simple multi constant case statement with duplicate enums
+ */
+ public void testBug543240_2() {
+ 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 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 7)\n" +
+ " case SUNDAY : System.out.println(Day.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,
+ null,
+ true,
+ options);
+ }
+ /*
+ * A simple multi constant case statement with duplicate enums
+ */
+ public void testBug543240_2a() {
+ 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 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 7)\n" +
+ " case SUNDAY, SATURDAY : \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,
+ null,
+ true,
+ options);
+ }
+ /*
+ *
+ */
+ public void testBug543240_3() {
+ 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 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.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] {"--enable-preview"},
+ options);
+ }
+ public void testBug543240_4() {
+ 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 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,
+ options,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Simple switch case with string literals
+ */
+ public void testBug543240_5() {
+ 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,
+ options,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug543240_6() {
+ 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\", \"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,
+ options,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Switch with multi constant case statements with string literals
+ * two string literals with same hashcode
+ */
+ public void testBug543240_7() {
+ 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(\"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,
+ options,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Switch with multi constant case statements with integer constants
+ */
+ public void testBug543240_8() {
+ 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,
+ options,
+ new String[] {"--enable-preview"});
+ }
+ /*
+ * Switch multi-constant with mixed constant types, reported
+ */
+ public void testBug543240_9() {
+ 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 testBug543240_10() {
+ 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.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ /*
+ * Switch multi-constant without break statement, reported
+ */
+ public void testBug543240_11() {
+ 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.runNegativeTest(
+ testFiles,
+ expectedProblemLog,
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ /*
+ * Switch multi-constant with duplicate int constants
+ */
+ public void testBug543240_12() {
+ 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 8)\n" +
+ " case 3, 4: \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 testBug543240_13() {
+ 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 8)\n" +
+ " case \"b\", \"c\": \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 testBug543240_14() {
+ 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 testBug543240_15() {
+ 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 testBug543240_16() {
+ 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 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.runNegativeTest(
+ testFiles,
+ "",
+ null,
+ true,
+ new String[] { "--enable-preview"},
+ options);
+ }
+ public void testBug543795_01() {
+ 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" +
+ " break 0;\n" +
+ " }\n" +
+ " case 2 : {\n" +
+ " break;\n" +
+ " }\n" +
+ " default : break 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 of a switch expression should have a value\n" +
+ "----------\n");
+ }
+ public void testBug543691() {
+ 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 testBug543799_1() {
+ 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 testBug543799_2() {
+ 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: break \"\";\n" +
+ " default: break 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 testBug543799_3() {
+ 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 testBug543799_4() {
+ 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 testBug543799_5() {
+ // 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 testSwitchStatementWithBreakExpression() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testSwitchStatementWithEnumValues() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug543967_01() {
+ 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 testBug544204() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544204_2() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544223() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544258_01() {
+ 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" +
+ " break today;\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY :\n" +
+ " today=2;\n" +
+ " break 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 testBug544253() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544254() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544254_2() {
+ 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",
+ customOptions,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544254_3() {
+ 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",
+ customOptions,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544224_1() {
+ 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,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544298() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544298_2() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544428_01() {
+ 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 testBug544523_01() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544560_01() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544458() {
+ 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; break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544458_2() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static int foo(int i) {\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1: i++; break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544458_3() {
+ 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; break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544458_4() {
+ 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;}; break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544458_5() {
+ 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); break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544601_1() {
+ 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" +
+ " break true;\n" +
+ " default: break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544556() {
+ 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 -> { break 2; }\n" +
+ " default -> { break 3; }\n" +
+ " }) {\n" +
+ " case 0 -> { break 0; }\n" +
+ " default -> { break 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug544702_01() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug545168_01() {
+ 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",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ public void testBug545255_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void foo (int i) {\n"+
+ " int v = switch (i) {\n"+
+ " case 60, 600: break 6;\n"+
+ " case 70: break 7;\n"+
+ " case 80: break 8;\n"+
+ " case 90, 900: break 9;\n"+
+ " default: break 0;\n"+
+ " };\n"+
+ " System.out.println(v);\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " X.foo(10);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0",
+ null,
+ new String[] {"--enable-preview"});
+ }
+ // see comment 12 in the bug
+ public void testBug513766_01() {
+ this.runNegativeTest(
+ 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",
+ },
+ "----------\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");
+ }
+ public void testBug545333() {
+ 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 testBug545518() {
+ 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.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 testBug545518a() {
+ if (this.complianceLevel < ClassFileConstants.JDK12)
+ return;
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE);
+ 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.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 testBug545518b() {
+ 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);
+ }
+}
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 cc7fc5fb1a..004768ede2 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
@@ -3106,6 +3106,30 @@ public void testBug533475() {
"}\n"
});
}
+public void testBug545518() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_8 || this.complianceLevel >= ClassFileConstants.JDK12)
+ return;
+ String message =
+ "----------\n" +
+ "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" +
+ "----------\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);
+}
public static Class testClass() {
return SwitchTest.class;
}
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 1b1baca7c6..0fd2a6bf58 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 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
@@ -172,12 +172,18 @@ public static Test suite() {
// add 10 specific test here (check duplicates)
ArrayList since_10 = new ArrayList();
since_10.add(JEP286Test.class);
+ since_10.add(Unicode10Test.class);
// add 11 specific test here (check duplicates)
ArrayList since_11 = new ArrayList();
since_11.add(JEP323VarLambdaParamsTest.class);
since_11.add(JEP181NestTest.class);
+ // add 12 specific test here (check duplicates)
+ ArrayList since_12 = new ArrayList();
+ since_12.add(SwitchExpressionTest.class);
+ since_12.add(Unicode11Test.class);
+
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
all.addTest(new TestSuite(StandAloneASTParserTest.class));
@@ -275,6 +281,20 @@ public static Test suite() {
TestCase.resetForgottenFilters(tests_11);
all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11), tests_11));
}
+ if ((possibleComplianceLevels & AbstractCompilerTest.F_12) != 0) {
+ ArrayList tests_12 = (ArrayList)standardTests.clone();
+ tests_12.addAll(since_1_4);
+ tests_12.addAll(since_1_5);
+ tests_12.addAll(since_1_6);
+ tests_12.addAll(since_1_7);
+ tests_12.addAll(since_1_8);
+ tests_12.addAll(since_9);
+ tests_12.addAll(since_10);
+ tests_12.addAll(since_11);
+ tests_12.addAll(since_12);
+ TestCase.resetForgottenFilters(tests_12);
+ all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12), tests_12));
+ }
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/Unicode11Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.java
new file mode 100644
index 0000000000..99940b1397
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.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 Unicode11Test extends AbstractRegressionTest {
+public Unicode11Test(String name) {
+ super(name);
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_12);
+}
+public void test1() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int a\u0560; // new unicode character in unicode 11.0 \n" +
+ "}",
+ },
+ "",
+ options);
+}
+public void test2() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int a\\u0560; // new unicode character in unicode 11.0 \n" +
+ "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " public int a\\u0560; // new unicode character in unicode 11.0 \n" +
+ " ^^^^^^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+}
+public static Class<Unicode11Test> testClass() {
+ return Unicode11Test.class;
+}
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
index d0e2f2824d..6e7d315d3c 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 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
@@ -50,7 +50,11 @@ public class VarargsTest extends AbstractComparableTest {
public static Class testClass() {
return VarargsTest.class;
}
-
+ protected String intersection(String... types) {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_8)
+ return String.join(" & ", types);
+ return String.join("&", types);
+ }
public void test001() {
this.runConformTest(
new String[] {
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 caca176995..170bb63642 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2018 IBM Corporation and others.
+ * Copyright (c) 2010, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -32,6 +32,7 @@ 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;
@@ -49,11 +50,13 @@ import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SwitchExpression;
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.tests.compiler.regression.AbstractRegressionTest;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@SuppressWarnings({ "rawtypes" })
public class StandAloneASTParserTest extends AbstractRegressionTest {
@@ -61,7 +64,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
super(name);
}
- private static final int AST_JLS_LATEST = AST.JLS11;
+ private static final int AST_JLS_LATEST = AST.JLS12;
public ASTNode runConversion(
int astLevel,
@@ -1755,5 +1758,41 @@ public class StandAloneASTParserTest extends AbstractRegressionTest {
SimpleName simpleName = (SimpleName) name;
assertFalse("A var", simpleName.isVar());
}
+ public void testBug545383_01() throws JavaModelException {
+ String contents =
+ "class X {\n"+
+ " public static int foo(int i) {\n"+
+ " int result = switch (i) {\n"+
+ " case 1 -> {break 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_12);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_12);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_12);
+ 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());
+ }
} \ No newline at end of file
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 fee9aacbe9..ace9a6a75a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 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
@@ -43,6 +43,7 @@ public class AbstractCompilerTest extends TestCase {
public static final int F_9 = 0x40;
public static final int F_10 = 0x80;
public static final int F_11 = 0x100;
+ public static final int F_12 = 0x200;
public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));
private static final int UNINITIALIZED = -1;
@@ -98,6 +99,9 @@ public class AbstractCompilerTest extends TestCase {
if ((complianceLevels & AbstractCompilerTest.F_11) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
+ }
}
/**
@@ -140,6 +144,9 @@ public class AbstractCompilerTest extends TestCase {
if ((complianceLevels & AbstractCompilerTest.F_11) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11)));
}
+ if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
+ suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
+ }
return suite;
}
@@ -148,7 +155,7 @@ public class AbstractCompilerTest extends TestCase {
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 = "12".equals(System.getProperty("java.specification.version"));
+ isJRE12Plus = isJRELevel(F_12);
}
/**
@@ -291,6 +298,14 @@ public class AbstractCompilerTest extends TestCase {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11)));
}
}
+ int level12 = complianceLevels & AbstractCompilerTest.F_12;
+ if (level12 != 0) {
+ if (level12 < minimalCompliance) {
+ System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance 12!");
+ } else {
+ suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12)));
+ }
+ }
return suite;
}
@@ -324,7 +339,7 @@ public class AbstractCompilerTest extends TestCase {
else if (highestLevel == ClassFileConstants.JDK1_3)
complianceString = "1.3";
else {
- highestLevel = ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11);
+ highestLevel = ClassFileConstants.getLatestJDKLevel();
if (highestLevel > 0) {
complianceString = CompilerOptions.versionFromJdkLevel(highestLevel);
} else {
@@ -349,6 +364,9 @@ public class AbstractCompilerTest extends TestCase {
*/
public static long highestComplianceLevels() {
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
+ if ((complianceLevels & AbstractCompilerTest.F_12) != 0) {
+ return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12);
+ }
if ((complianceLevels & AbstractCompilerTest.F_11) != 0) {
return ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11);
}
@@ -402,10 +420,10 @@ public class AbstractCompilerTest extends TestCase {
public static int getPossibleComplianceLevels() {
if (possibleComplianceLevels == UNINITIALIZED) {
String specVersion = System.getProperty("java.specification.version");
- isJRE9Plus = CompilerOptions.VERSION_9.equals(specVersion)
- || CompilerOptions.VERSION_10.equals(specVersion)
- || CompilerOptions.VERSION_11.equals(specVersion);
- isJRE11Plus = CompilerOptions.VERSION_11.equals(specVersion);
+ isJRE12Plus = CompilerOptions.VERSION_12.equals(specVersion);
+ isJRE11Plus = isJRE12Plus || CompilerOptions.VERSION_11.equals(specVersion);
+ isJRE9Plus = isJRE11Plus || CompilerOptions.VERSION_9.equals(specVersion)
+ || CompilerOptions.VERSION_10.equals(specVersion);
initReflectionVersion();
String compliances = System.getProperty("compliance");
if (compliances != null) {
@@ -429,6 +447,8 @@ public class AbstractCompilerTest extends TestCase {
possibleComplianceLevels |= F_10;
} else if (CompilerOptions.VERSION_11.equals(compliance)) {
possibleComplianceLevels |= F_11;
+ } else if (CompilerOptions.VERSION_12.equals(compliance)) {
+ possibleComplianceLevels |= F_12;
} else {
System.out.println("Ignoring invalid compliance (" + compliance + ")");
System.out.print("Use one of ");
@@ -441,7 +461,8 @@ public class AbstractCompilerTest extends TestCase {
System.out.print(CompilerOptions.VERSION_1_8 + ", ");
System.out.print(CompilerOptions.VERSION_9 + ", ");
System.out.print(CompilerOptions.VERSION_10 + ", ");
- System.out.println(CompilerOptions.VERSION_11);
+ System.out.print(CompilerOptions.VERSION_11 + ", ");
+ System.out.println(CompilerOptions.VERSION_12);
}
}
if (possibleComplianceLevels == 0) {
@@ -487,6 +508,10 @@ public class AbstractCompilerTest extends TestCase {
if (canRun11) {
possibleComplianceLevels |= F_11;
}
+ boolean canRun12 = canRun11 && !CompilerOptions.VERSION_11.equals(specVersion);
+ if (canRun12) {
+ possibleComplianceLevels |= F_12;
+ }
} else if ("1.0".equals(specVersion)
|| CompilerOptions.VERSION_1_1.equals(specVersion)
|| CompilerOptions.VERSION_1_2.equals(specVersion)
@@ -507,6 +532,9 @@ public class AbstractCompilerTest extends TestCase {
possibleComplianceLevels |= F_10;
if (!CompilerOptions.VERSION_10.equals(specVersion)) {
possibleComplianceLevels |= F_11;
+ if (!CompilerOptions.VERSION_11.equals(specVersion)) {
+ possibleComplianceLevels |= F_12;
+ }
}
}
}
@@ -662,6 +690,8 @@ public class AbstractCompilerTest extends TestCase {
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10);
} else {
+ // This is already good enough to cover versions from future
+ // (as long as versionFromJdkLevel does its job)
String ver = CompilerOptions.versionFromJdkLevel(this.complianceLevel);
options.put(CompilerOptions.OPTION_Compliance, ver);
options.put(CompilerOptions.OPTION_Source, ver);
@@ -683,6 +713,11 @@ public class AbstractCompilerTest extends TestCase {
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";
+ if (compliance > ClassFileConstants.JDK10) {
+ String ver = CompilerOptions.versionFromJdkLevel(compliance);
+ 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
return version;
}
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar
new file mode 100644
index 0000000000..eed2c4df78
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.zip
new file mode 100644
index 0000000000..35e5589d58
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip
new file mode 100644
index 0000000000..35e5589d58
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin12src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
index df361f565f..bb48557698 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
index 23ce774f5e..031b53aa47 100644
--- a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
+++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin9src.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin12.jar b/org.eclipse.jdt.core.tests.model/JCL/jclMin12.jar
new file mode 100644
index 0000000000..0f621d1524
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin12.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin12src.zip b/org.eclipse.jdt.core.tests.model/JCL/jclMin12src.zip
new file mode 100644
index 0000000000..bf05b46301
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin12src.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 dd9c7e2634..768572d3c6 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -139,6 +139,37 @@
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11</tycho.surefire.argLine>
</properties>
</profile>
+ <profile>
+ <id>test-on-javase-12</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-12</id>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-12/configure -->
+ <tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12</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
new file mode 100644
index 0000000000..eabf761ddc
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava12Tests.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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 org.eclipse.jdt.core.tests.dom.ASTConverter12Test;
+import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
+import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunAllJava12Tests extends TestCase {
+
+ public RunAllJava12Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ // to be filled after other tests are added
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+ ASTConverter12Test.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(RunAllJava12Tests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ addTestsToSuite(ts, testClasses);
+ testClasses = getConverterTestClasses();
+ addTestsToSuite(ts, testClasses);
+
+ AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_11);
+ 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
new file mode 100644
index 0000000000..11bc2fa141
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava12Tests.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.dom.ASTConverter12Test;
+import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class RunOnlyJava12Tests extends TestCase {
+
+ public RunOnlyJava12Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ // to be filled after other tests are added
+ };
+ }
+
+ 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) {
+
+ 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/ASTConverter12Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java
new file mode 100644
index 0000000000..7efc9f1f36
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter12Test.java
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * 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.dom;
+
+import java.util.List;
+
+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.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+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.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.Type;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+
+import junit.framework.Test;
+
+@SuppressWarnings("rawtypes")
+public class ASTConverter12Test extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(getAST12());
+ }
+
+ public ASTConverter12Test(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 19 };
+// TESTS_RANGE = new int[] { 1, -1 };
+// TESTS_NAMES = new String[] {"test0001"};
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverter12Test.class);
+ }
+
+ static int getAST12() {
+ return AST.JLS12;
+ }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+ /*
+ * Test that a simple switch expression's return type holds the correct type
+ */
+ public void test0001() throws JavaModelException {
+ String contents =
+ " public class X {\n" +
+ " enum Day\n" +
+ " {\n" +
+ " SUNDAY, MONDAY, TUESDAY, WEDNESDAY,\n" +
+ " THURSDAY, FRIDAY, SATURDAY;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " Day day = Day.SUNDAY;\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ "\n" +
+ " case WEDNESDAY -> {break 10;}\n" +
+ " default -> {\n" +
+ " int g = day.toString().length();\n" +
+ " break g;\n" +
+ " }};\n" +
+ " System.out.println(k);\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ VariableDeclarationStatement vStmt1 = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(1);
+ Type type = vStmt1.getType();
+ IBinding binding = type.resolveBinding();
+ assertTrue("null binding", binding != null);
+ assertTrue("binding incorrect", binding.getName().equals("int"));
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ /*
+ * Test that a case statement with multiple cases is resolved correctly
+ * and has the correct source range
+ */
+ public void test0002() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String aa(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY ->\n" +
+ " today=\"Weekend\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->\n" +
+ " today=\"Working\";\n" +
+ " default ->\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ " \n" +
+ " String bb(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " today = \"Weekend day\";\n" +
+ " break;\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " today = \"Working day\";\n" +
+ " break;\n" +
+ " default:\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ checkSourceRange((Statement) switchStatement.statements().get(0), "case SATURDAY,SUNDAY ->", contents);
+ checkSourceRange((Statement) switchStatement.statements().get(2), "case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->", contents);
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+
+ /* test implicit break statement */
+
+ public void test0003() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String aa(Day day) throws Exception {\n" +
+ " var today = \"\";\n" +
+ " switch (day) {\n" +
+ " case SATURDAY,SUNDAY ->\n" +
+ " today=\"Weekend\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY ->\n" +
+ " today=\"Working\";\n" +
+ " default ->\n" +
+ " throw new Exception(\"Invalid day: \" + day.name());\n" +
+ " }\n" +
+ " return today;\n" +
+ " }\n" +
+ " \n" +
+ " String bb(Day day) throws Exception {\n" +
+ " String today = \"\";\n" +
+ " today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " break \"Weekend day\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " break \"Week day\";\n" +
+ " default:\n" +
+ " break \"Any day\";\n" +
+ " };\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.SWITCH_STATEMENT);
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ checkSourceRange((Statement) switchStatement.statements().get(0), "case SATURDAY,SUNDAY ->", contents);
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ public void test0004() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " static enum Day {MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, SATURDAY,SUNDAY}\n" +
+ " String bb(Day day) throws Exception {\n" +
+ " String today = switch (day) {\n" +
+ " case SATURDAY,SUNDAY:\n" +
+ " break \"Weekend day\";\n" +
+ " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY:\n" +
+ " break \"Week day\";\n" +
+ " default:\n" +
+ " break \"Any day\";\n" +
+ " };\n" +
+ " return today;\n" +
+ " }\n" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1, 0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("incorrect type", ASTNode.SWITCH_EXPRESSION, initializer.getNodeType());
+ Expression expression = ((SwitchExpression) initializer).getExpression();
+ assertEquals("incorrect type", ASTNode.SIMPLE_NAME, expression.getNodeType());
+ assertEquals("incorrect name", "day", ((SimpleName) expression).getFullyQualifiedName());
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ BreakStatement brStmt = (BreakStatement) statements.get(1);
+ Expression expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ //default case:
+ SwitchCase caseStmt = (SwitchCase) statements.get(4);
+ assertTrue("not default", caseStmt.isDefault());
+ brStmt = (BreakStatement) statements.get(5);
+ expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ public void test0005() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " int i = 0;\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 -> \"odd\";\n" +
+ " case 1 -> \"even\";\n" +
+ " default -> \"\";\n" +
+ " };\n" +
+ " return ret;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("incorrect type", ASTNode.SWITCH_EXPRESSION, initializer.getNodeType());
+ Expression expression = ((SwitchExpression) initializer).getExpression();
+ assertEquals("incorrect type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ BreakStatement brStmt = (BreakStatement) statements.get(1);
+ Expression expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ //default case:
+ SwitchCase caseStmt = (SwitchCase) statements.get(4);
+ assertTrue("not default", caseStmt.isDefault());
+ brStmt = (BreakStatement) statements.get(5);
+ expression2 = brStmt.getExpression();
+ assertNotNull("should not null", expression2);
+ assertEquals("incorrect node type", ASTNode.STRING_LITERAL, expression2.getNodeType());
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
+ public void test0006() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public String test001() {\n" +
+ " int i = 0;\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 -> {return \"odd\"; }\n" +
+ " case 1 -> \"even\";\n" +
+ " default -> \"\";\n" +
+ " };\n" +
+ " return ret;\n" +
+ " }" +
+ "}" ;
+ this.workingCopy = getWorkingCopy("/Converter12/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, 1);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ List fragments = ((VariableDeclarationStatement) node).fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Switch statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ List statements = ((SwitchExpression) initializer).statements();
+ assertEquals("incorrect no of statements", 6, statements.size());
+ Block block = (Block) statements.get(1);
+ statements = block.statements();
+ assertEquals("incorrect no of statements", 1, statements.size());
+ Statement stmt = (Statement) statements.get(0);
+ assertEquals("incorrect node type", ASTNode.RETURN_STATEMENT, stmt.getNodeType());
+
+ } 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/ASTConverter15JLS4Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java
index dc6db31f4a..21383f0431 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java
@@ -4829,12 +4829,14 @@ public class ASTConverter15JLS4Test extends ConverterTestSetup {
statement = (Statement) statements.get(0);
assertEquals("Not a switch case statement", ASTNode.SWITCH_CASE, statement.getNodeType());
SwitchCase switchCase = (SwitchCase) statement;
+ @SuppressWarnings("deprecation")
Expression expression = switchCase.getExpression();
assertNull("Got a constant", expression.resolveConstantExpressionValue());
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
- public void test0152() throws CoreException {
+ @SuppressWarnings("deprecation")
+ public void test0152() throws CoreException {
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
String contents =
"public class X {\n" +
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java
index 32ef339415..546c5a585a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java
@@ -4759,7 +4759,8 @@ public class ASTConverter15JLS8Test extends ConverterTestSetup {
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
- public void test0151() throws CoreException {
+ @SuppressWarnings("deprecation")
+ public void test0151() throws CoreException {
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
String contents =
"public enum X {\n" +
@@ -4822,7 +4823,8 @@ public class ASTConverter15JLS8Test extends ConverterTestSetup {
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
- public void test0152() throws CoreException {
+ @SuppressWarnings("deprecation")
+ public void test0152() throws CoreException {
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
String contents =
"public class X {\n" +
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index 3a42702693..00cd53b3be 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -4781,7 +4781,8 @@ public class ASTConverter15Test extends ConverterTestSetup {
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
- public void test0151() throws CoreException {
+ @SuppressWarnings("deprecation")
+ public void test0151() throws CoreException {
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
String contents =
"public enum X {\n" +
@@ -4844,7 +4845,8 @@ public class ASTConverter15Test extends ConverterTestSetup {
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
- public void test0152() throws CoreException {
+ @SuppressWarnings("deprecation")
+ public void test0152() throws CoreException {
this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
String contents =
"public class X {\n" +
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 6321d365c7..550672a29e 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2018 IBM Corporation and others.
+ * Copyright (c) 2016, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -37,6 +37,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.IProblem;
@SuppressWarnings({"rawtypes"})
public class ASTConverter9Test extends ConverterTestSetup {
@@ -1414,5 +1415,93 @@ 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);
+ }
+ }
// Add new tests here
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
index addae41c47..f4d1f0ef49 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
@@ -2088,6 +2088,7 @@ public class ASTConverterAST3Test extends ConverterTestSetup {
/**
* SwitchStatement ==> SwitchStatement
*/
+ @SuppressWarnings("deprecation")
public void test0097() throws JavaModelException {
ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
char[] source = sourceUnit.getSource().toCharArray();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java
index 926d8a34bd..4b77b6e96a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java
@@ -2088,6 +2088,7 @@ public class ASTConverterAST4Test extends ConverterTestSetup {
/**
* SwitchStatement ==> SwitchStatement
*/
+ @SuppressWarnings("deprecation")
public void test0097() throws JavaModelException {
ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
char[] source = sourceUnit.getSource().toCharArray();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java
index 9c83e01fce..9e617b11bd 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java
@@ -2072,6 +2072,7 @@ public class ASTConverterAST8Test extends ConverterTestSetup {
/**
* SwitchStatement ==> SwitchStatement
*/
+ @SuppressWarnings("deprecation")
public void test0097() throws JavaModelException {
ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
char[] source = sourceUnit.getSource().toCharArray();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
index acbd8ddf23..dfafd6d6a9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
@@ -2177,6 +2177,7 @@ public class ASTConverterTest extends ConverterTestSetup {
/**
* SwitchStatement ==> SwitchStatement
*/
+ @SuppressWarnings("deprecation")
public void test0097() throws JavaModelException {
ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
char[] source = sourceUnit.getSource().toCharArray();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
index 04ca9bb6e8..6b421b9407 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
@@ -1206,6 +1206,7 @@ public class ASTMatcherTest extends org.eclipse.jdt.core.tests.junit.extension.T
x1.setName(this.N2);
basicMatch(x1);
}
+ @SuppressWarnings("deprecation")
public void testSwitchCase() {
SwitchCase x1 = this.ast.newSwitchCase();
x1.setExpression(this.E1);
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 667df5dfb2..43c975a04f 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
@@ -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
@@ -8868,6 +8868,7 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase
ASTNode.USES_DIRECTIVE,
ASTNode.PROVIDES_DIRECTIVE,
ASTNode.MODULE_MODIFIER,
+ ASTNode.SWITCH_EXPRESSION,
};
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
index 0407d10cc6..c5e62c6311 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
@@ -2096,6 +2096,7 @@ public class ASTVisitorTest extends org.eclipse.jdt.core.tests.junit.extension.T
String result = this.b.toString();
assertTrue(result.equals("[(eSMR"+this.N1S+this.N2S+"eSMR)]")); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @SuppressWarnings("deprecation")
public void testSwitchCase() {
SwitchCase x1 = this.ast.newSwitchCase();
x1.setExpression(this.E1);
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 b6fafe483c..65102b4e48 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2018 IBM Corporation and others.
+ * Copyright (c) 2004, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -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_11)) {
+ 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;
} else if (jdkLevel >= ClassFileConstants.JDK10) {
JLSLevel = AST_INTERNAL_JLS10;
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 f34d73e568..47ab610d98 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 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
@@ -105,6 +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$
PROJECT_SETUP = false;
} else {
TEST_SUITES.remove(getClass());
@@ -117,6 +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$
PROJECT_SETUP = false;
}
}
@@ -178,6 +180,14 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
new IPath[] {getConverterJCLPath("11"), getConverterJCLSourcePath("11"), getConverterJCLRootSourcePath()},
null);
}
+ } else if ("12".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("CONVERTER_JCL12_LIB") == null) {
+ setupExternalJCL("converterJclMin12");
+ JavaCore.setClasspathVariables(
+ new String[] {"CONVERTER_JCL11_LIB", "CONVERTER_JCL11_SRC", "CONVERTER_JCL11_SRCROOT"},
+ new IPath[] {getConverterJCLPath("12"), getConverterJCLSourcePath("12"), getConverterJCLRootSourcePath()},
+ null);
+ }
} else if (JavaCore.getClasspathVariable("CONVERTER_JCL_LIB") == null) {
setupExternalJCL("converterJclMin");
JavaCore.setClasspathVariables(
@@ -202,6 +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$
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 028e170023..f12cc67bab 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,6 +52,7 @@ public static Class[] getAllTestClasses() {
TypeAnnotationsConverterTest.class,
ASTConverter18Test.class,
ASTConverter9Test.class,
+ ASTConverter12Test.class,
};
}
public static Test suite() {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index 36ec699cc1..678c648075 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Brock Janiczak - Contribution for bug 150741
@@ -14837,4 +14837,79 @@ public void testBug541011g() throws JavaModelException {
String input = getCompilationUnit("Formatter", "", "test541011", "in.java").getSource();
formatSource(input, getCompilationUnit("Formatter", "", "test541011", "G_out.java").getSource());
}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818a() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "A_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818b() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "B_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818c() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "C_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818d() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ this.formatterPrefs.brace_position_for_switch = DefaultCodeFormatterConstants.NEXT_LINE;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "D_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818e() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "E_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818f() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ 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;
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "F_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543818 - [12] Formatter Support for Switch Expressions
+ */
+public void testBug543818g() throws JavaModelException {
+ setComplianceLevel(CompilerOptions.VERSION_12);
+ String input = getCompilationUnit("Formatter", "", "test543818", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543818", "G_out.java").getSource());
+}
}
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 72600309b7..3bc7436e67 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
@@ -90,11 +90,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
}
}
long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion.length() > 3 ? javaVersion.substring(0, 3) : javaVersion);
+ if (jdkLevel >= ClassFileConstants.getLatestJDKLevel()) {
+ isJRE12 = true;
+ }
if (jdkLevel >= ClassFileConstants.JDK11) {
- if (CompilerOptions.versionToJdkLevel(javaVersion.length() > 3 ? javaVersion.substring(0, 3) : javaVersion, false) == 0) {
- // version was capped to 11 during versionToJdkLevel(version, true)
- isJRE12 = true;
- }
isJRE11 = true;
}
if (jdkLevel >= ClassFileConstants.JDK10) {
@@ -114,7 +113,7 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
"jdk.packager,jdk.packager.services,jdk.plugin.dom," + // not present in OpenJDK
"jdk.scripting.nashorn,jdk.sctp,jdk.security.auth,jdk.security.jgss,jdk.unsupported,jdk.xml.dom," +
"oracle.desktop,oracle.net"; // not present in OpenJDK
- } else if (vmName.contains("OpenJDK")) {
+ } else if (vmName.contains("OpenJDK") || vmName.contains("OpenJ9")) {
DEFAULT_MODULES = "java.se," +
"jdk.accessibility,jdk.attach,jdk.compiler,jdk.dynalink,jdk.httpserver," +
"jdk.incubator.httpclient,jdk.jartool,jdk.javadoc,jdk.jconsole,jdk.jdi," +
@@ -124,7 +123,7 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
System.out.println(System.getProperties());
fail("Unexpected java vm "+javaVersion+" "+vmName);
}
- System.out.println("Recognized Java 9 version '"+javaVersion+"' with vm.name '"+vmName+"'");
+ System.out.println("Recognized Java version '"+javaVersion+"' with vm.name '"+vmName+"'");
}
}
@@ -142,11 +141,16 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
protected static final int AST_INTERNAL_JLS10 = AST.JLS10;
/**
+ * Internal synonym for constant AST.JSL12
+ * to alleviate deprecation warnings once AST.JLS12 is deprecated in future.
+ */
+ protected static final int AST_INTERNAL_JLS12 = AST.JLS12;
+
+ /**
* Internal synonym for constant AST.JSL11
* to alleviate deprecation warnings once AST.JLS11 is deprecated in future.
*/
protected static final int AST_INTERNAL_JLS11 = AST.JLS11;
-
public static class BasicProblemRequestor implements IProblemRequestor {
public void acceptProblem(IProblem problem) {}
public void beginReporting() {}
@@ -2044,6 +2048,12 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11);
javaProject.setOptions(options);
+ } else if ("12".equals(compliance)) {
+ Map options = new HashMap();
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12);
+ javaProject.setOptions(options);
}
result[0] = javaProject;
}
@@ -3119,6 +3129,7 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
javaProject.setOption(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.IGNORE);
javaProject.setOption(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.IGNORE);
javaProject.setOption(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING, JavaCore.IGNORE);
+// javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
return javaProject;
}
protected void setUpProjectCompliance(IJavaProject javaProject, String compliance) throws JavaModelException, IOException {
@@ -3136,7 +3147,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
newJclLibString = "JCL18_FULL";
newJclSrcString = "JCL18_SRC"; // Use the same source
} else {
- if (compliance.equals("11")) {
+ if (compliance.equals("12")) {
+ newJclLibString = "JCL12_LIB";
+ newJclSrcString = "JCL12_SRC";
+ } else if (compliance.equals("11")) {
newJclLibString = "JCL11_LIB";
newJclSrcString = "JCL11_SRC";
} else if (compliance.equals("10")) {
@@ -3193,10 +3207,11 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
IPath jcl9Lib = new Path("JCL19_LIB");
IPath jcl10Lib = new Path("JCL10_LIB");
IPath jcl11Lib = new Path("JCL11_LIB");
+ IPath jcl12Lib = new Path("JCL12_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(jclFull);
+ || path.equals(jcl10Lib) || path.equals(jcl11Lib) || path.equals(jcl12Lib) || path.equals(jclFull);
}
public void setUpJCLClasspathVariables(String compliance) throws JavaModelException, IOException {
setUpJCLClasspathVariables(compliance, false);
@@ -3259,6 +3274,14 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
new IPath[] {getExternalJCLPath("11"), getExternalJCLSourcePath("11"), getExternalJCLRootSourcePath()},
null);
}
+ } else if ("12".equals(compliance)) {
+ if (JavaCore.getClasspathVariable("JCL12_LIB") == null) {
+ setupExternalJCL("jclMin12");
+ JavaCore.setClasspathVariables(
+ new String[] {"JCL12_LIB", "JCL12_SRC", "JCL_SRCROOT"},
+ new IPath[] {getExternalJCLPath("12"), getExternalJCLSourcePath("12"), getExternalJCLRootSourcePath()},
+ null);
+ }
} else {
if (JavaCore.getClasspathVariable("JCL_LIB") == null) {
setupExternalJCL("jclMin");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
index 2f58097d50..5f37bc32c8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 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
@@ -102,6 +102,7 @@ private static Class[] getAllTestClasses() {
ResolveTests2.class,
ResolveTests_1_5.class,
ResolveTests18.class,
+ ResolveTests12.class,
SelectionJavadocModelTests.class,
// Support for completion tests
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java
index a7d9e60fac..ba4462e602 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java
@@ -1903,6 +1903,7 @@ public void testModule2() throws CoreException, IOException {
System.err.println(this.getClass().getName()+'.'+getName()+" needs a Java 9 JRE - skipped");
return;
}
+ if (isJRE12) return;
try {
IJavaProject prj = createJava9Project("Test", new String[]{"src"});
String moduleSrc =
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java
new file mode 100644
index 0000000000..ea0370267a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests12.java
@@ -0,0 +1,856 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
+
+import junit.framework.Test;
+
+public class CompletionTests12 extends AbstractJavaModelCompletionTests {
+
+ static {
+// TESTS_NAMES = new String[]{"test018e"};
+ }
+
+ public CompletionTests12(String name) {
+ super(name);
+ }
+ public void setUpSuite() throws Exception {
+ if (COMPLETION_PROJECT == null) {
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "12");
+ } else {
+ setUpProjectCompliance(COMPLETION_PROJECT, "12");
+ }
+ super.setUpSuite();
+ }
+ public static Test suite() {
+ return buildModelTestSuite(CompletionTests12.class);
+ }
+ public void test001() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUN ->\n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATURDAY, SUN";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test002() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUN :\n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATURDAY, SUN";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test003() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATU -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SATU";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SATURDAY[FIELD_REF]{SATURDAY, LMyDay;, LMyDay;, SATURDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test004() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY, MOND -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "MOND";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test005() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUND, MONDAY -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "SUND";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "SUNDAY[FIELD_REF]{SUNDAY, LMyDay;, LMyDay;, SUNDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test005a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day) {\n" +
+ " case SATURDAY, SUNDAY -> \n" +
+ " System.out.println(day.toString());\n" +
+ " case MON -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY, MONDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "case MON";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "MONDAY[FIELD_REF]{MONDAY, LMyDay;, LMyDay;, MONDAY, null, "+
+ (RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING+
+ RelevanceConstants.R_CASE + RelevanceConstants.R_EXACT_EXPECTED_TYPE +
+ RelevanceConstants.R_ENUM + RelevanceConstants.R_ENUM_CONSTANT +
+ RelevanceConstants.R_UNQUALIFIED + RelevanceConstants.R_NON_RESTRICTED)+ "}",
+ requestor.getResults());
+ }
+ public void test006() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day.toS) {\n" +
+ " case \"SATURDAY\" -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.toS";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}",
+ requestor.getResults());
+ }
+ public void test007() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (day.o) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.o";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 60}",
+ requestor.getResults());
+ }
+ public void test008() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + day.o) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.o";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ordinal[METHOD_REF]{ordinal(), Ljava.lang.Enum<LMyDay;>;, ()I, ordinal, null, 90}",
+ requestor.getResults());
+ }
+ public void test009() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + da) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "1 + da";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
+ requestor.getResults());
+ }
+ public void test010() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(MyDay day) {\n" +
+ " switch (1 + da + 1) {\n" +
+ " case 0 -> \n" +
+ " System.out.println(day.toString());\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "enum MyDay { SATURDAY, SUNDAY}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "1 + da";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "day[LOCAL_VARIABLE_REF]{day, null, LMyDay;, day, null, 52}",
+ requestor.getResults());
+ }
+ public void test011() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (arg) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "switch (arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test012() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (arg0) {\n" +
+ " case 1 -> arg;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test013() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Switch.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (0 + arg) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "0 + arg";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 82}",
+ requestor.getResults());
+ }
+ public void test014() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " swi);\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "swi";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "switch[KEYWORD]{switch, null, null, switch, null, 49}",
+ requestor.getResults());
+ }
+ public void _test015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> {break ar;}\n" +
+ " default -> 0;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void test016() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> {break 1;}\n" +
+ " default -> ar;\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void _test017() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " int arg1 = 0;\n" +
+ " foo(\n" +
+ " switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break ar;}\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}",
+ requestor.getResults());
+ }
+ public void _test017a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class Switch {\n" +
+ " public static void bar(int arg0) {\n" +
+ " foo(\n" +
+ " argLabel: switch (0 + arg0) {\n" +
+ " case 1 -> 1;\n" +
+ " default -> {break ar;}\n" +
+ " }\n" +
+ " });\n" +
+ " public static void foo(int arg0) {\n" +
+ " bar(MyDay.SUNDAY);\n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "break ar";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "arg0[LOCAL_VARIABLE_REF]{arg0, null, I, arg0, null, 52}\n" +
+ "argLabel[LABEL_REF]{argLabel, null, null, argLabel, null, 49}",
+ requestor.getResults());
+ }
+ public void test018a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.function.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> this::n_; \n" +
+ " case 2 -> () -> n1(); \n" +
+ " case 3 -> null; \n" +
+ " case 4 -> () -> n2(); \n" +
+ " default -> this::n2; }); \n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test018b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 2 -> () -> n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "-> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " default -> this::n_; }); \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test018d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " default -> () -> n_; }); \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "() -> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> this::n_1; \n" +
+ " case 2 -> () -> n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "() -> n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[LOCAL_VARIABLE_REF]{n_1, null, Ljava.lang.Object;, n_1, null, 51}\n" +
+ "n_1[METHOD_REF]{n_1(), LX;, ()LIN1;, n_1, null, 52}\n" +
+ "n_2[METHOD_REF]{n_2(), LX;, ()LIN2;, n_2, null, 52}",
+ requestor.getResults());
+ }
+ public void test018f() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "interface IN0 {} \n" +
+ "interface IN1 extends IN0 {} \n" +
+ "interface IN2 extends IN0 {}\n" +
+ "public class X {\n" +
+ " @NonNull IN1 n_1() { return new IN1() {}; } \n" +
+ " IN2 n_2() { return null; } \n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ " void testSw(int i) { \n" +
+ " m(switch(i) { \n" +
+ " case 1 -> () -> n_1; \n" +
+ " case 2 -> this::n_; \n" +
+ " }\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this::n_";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "n_1[METHOD_NAME_REFERENCE]{n_1, LX;, ()LIN1;, n_1, null, 60}\n" +
+ "n_2[METHOD_NAME_REFERENCE]{n_2, LX;, ()LIN2;, n_2, null, 60}",
+ requestor.getResults());
+ }
+ public void test019() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ " <M> void m(@NonNull Supplier<@NonNull M> m2) { } \n" +
+ "public class X {\n" +
+ " void testSw(int i) { \n" +
+ " m(swi);\n" +
+ "}\n" +
+ "interface Supplier<T> {\n" +
+ " T get();\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "swi";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "switch[KEYWORD]{switch, null, null, switch, null, 49}",
+ requestor.getResults());
+ }
+ public void test020() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " static final String THURSDAY = \"THURSDAY\";\n" +
+ " static final String FRIDAY = \"FRIDAY\";\n" +
+ " static final String SATURDAY = \"SATURDAY\";\n" +
+ " static final String SUNDAY = \"SUNDAY\"; \n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = \"MONDAY\";\n" +
+ " switch (day) {\n" +
+ " case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " case WEDNESDAY -> System.out.println(9);\n" +
+ " }\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {break 10;}\n" +
+ " default -> {\n" +
+ " int g = day.h();\n" +
+ " int result = f(g);\n" +
+ " break result;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.h";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
+ requestor.getResults());
+ }
+ public void test021() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "public class X {\n" +
+ " static final String MONDAY = \"MONDAY\";\n" +
+ " static final String TUESDAY = \"TUESDAY\";\n" +
+ " static final String WEDNESDAY = \"WEDNESDAY\";\n" +
+ " static final String THURSDAY = \"THURSDAY\";\n" +
+ " static final String FRIDAY = \"FRIDAY\";\n" +
+ " static final String SATURDAY = \"SATURDAY\";\n" +
+ " static final String SUNDAY = \"SUNDAY\"; \n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void main(String[] args) {\n" +
+ " String day = \"MONDAY\";\n" +
+ " int k = switch (day) {\n" +
+ " case MONDAY -> throw new NullPointerException();\n" +
+ " case TUESDAY -> 1;\n" +
+ " case WEDNESDAY -> {break 10;}\n" +
+ " default -> {\n" +
+ " int g = day.h();\n" +
+ " int result = f(g);\n" +
+ " break result;\n" +
+ " }};\n" +
+ " }\n" +
+ " static int f(int k) {\n" +
+ " return k*k;\n" +
+ " }\n" +
+ "}");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "day.h";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode, Ljava.lang.Object;, ()I, hashCode, null, 90}",
+ requestor.getResults());
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java
index e5d2894558..0fb4f79cdb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaCoreOptionsTests.java
@@ -120,10 +120,11 @@ public void test5() {
assertTrue(JavaCore.compareJavaVersions("9", "1.8") > 0);
assertTrue(JavaCore.compareJavaVersions("9.0.1", "9.1.2") == 0);
assertTrue(JavaCore.compareJavaVersions("9", "9.1.2") == 0);
+ assertTrue(JavaCore.compareJavaVersions("12", "11") > 0);
+ assertTrue(JavaCore.compareJavaVersions("12", "1.5") > 0);
String latest = JavaCore.latestSupportedJavaVersion();
String latestPlus = "" + (Integer.parseInt(latest) + 1);
assertTrue(JavaCore.compareJavaVersions(latest, latestPlus) == 0);
-
}
}
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
new file mode 100644
index 0000000000..c1fced3a0f
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs12Tests.java
@@ -0,0 +1,626 @@
+/*******************************************************************************
+ * 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/JavaSearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
index 8e5d3b4348..39cde45638 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 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
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
index ddc65ad408..2a4edf1f0e 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
@@ -60,8 +60,8 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
}
static {
-// TESTS_NAMES = new String[] { "testBug522330" };
- }
+// TESTS_NAMES = new String[] { "testReleaseOption8" };
+ }
private String sourceWorkspacePath = null;
protected ProblemRequestor problemRequestor;
public static Test suite() {
@@ -4963,10 +4963,10 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
getWorkingCopy("/Test/src/X.java", src, true);
assertProblems("should have not problems",
"----------\n" +
- "1. WARNING in /Test/src/X.java (at line 1)\n" +
+ "1. ERROR in /Test/src/X.java (at line 1)\n" +
" import java.*;\n" +
" ^^^^\n" +
- "The import java is never used\n" +
+ "The package java is not accessible\n" +
"----------\n",
this.problemRequestor);
} finally {
@@ -6184,6 +6184,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
}
public void testBug526054() throws Exception {
+ if (!isJRE9) return;
ClasspathJrt.resetCaches();
try {
// jdk.rmic is not be visible to code in an unnamed module, but using requires we can see the module.
@@ -6807,6 +6808,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
}
}
public void testBug527569c() throws CoreException {
+ if (!isJRE9) return;
IJavaProject p1 = createJava9Project("Bug527569", "1.7");
Map<String, String> options = new HashMap<>();
// Make sure the new options map doesn't reset.
@@ -6856,6 +6858,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
}
}
public void testBug527569e() throws CoreException {
+ if (!isJRE9 || isJRE12) return;
IJavaProject p1 = createJava9Project("Bug527569", "1.8");
Map<String, String> options = new HashMap<>();
// Make sure the new options map doesn't reset.
@@ -7650,39 +7653,39 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
}
}
public void testBug543195() throws CoreException {
- IJavaProject pj1 = createJava9Project("p1");
- IJavaProject pj2 = createJava9Project("p2");
+ IJavaProject pj1 = createJava9Project("pj1");
+ IJavaProject pj2 = createJava9Project("pj2");
IJavaProject ptest = createJava9Project("ptest");
try {
addModularProjectEntry(pj2, pj1);
addModularProjectEntry(ptest, pj2);
- createFolder("p1/src/p");
- createFile("p1/src/p/Missing.java",
+ createFolder("pj1/src/p");
+ createFile("pj1/src/p/Missing.java",
"package p;\n" +
"public class Missing {\n" +
" public void miss() {}\n" +
"}\n");
- createFile("p1/src/module-info.java",
- "module p1 {\n" +
+ createFile("pj1/src/module-info.java",
+ "module pj1 {\n" +
" exports p;\n" +
"}\n");
- createFolder("p2/src/q");
- createFile("p2/src/q/API.java",
+ createFolder("pj2/src/q");
+ createFile("pj2/src/q/API.java",
"package q;\n" +
"public class API extends p.Missing {}\n");
- createFile("p2/src/q/API2.java",
+ createFile("pj2/src/q/API2.java",
"package q;\n" +
"public class API2 extends API {}\n");
- createFile("p2/src/module-info.java",
- "module p2 {\n" +
- " requires p1;\n" +
+ createFile("pj2/src/module-info.java",
+ "module pj2 {\n" +
+ " requires pj1;\n" +
" exports q;\n" +
"}\n");
getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
- deleteFile("p1/bin/p/Missing.class");
+ deleteFile("pj1/bin/p/Missing.class");
pj1.getProject().close(null);
createFolder("ptest/src/p/r");
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12.java
new file mode 100644
index 0000000000..6caa19084a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12.java
@@ -0,0 +1,608 @@
+/*******************************************************************************
+ * 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.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
+
+import junit.framework.Test;
+
+public class ResolveTests12 extends AbstractJavaModelTests {
+ ICompilationUnit wc = null;
+
+static {
+// TESTS_NAMES = new String[] { "test018" };
+ // TESTS_NUMBERS = new int[] { 124 };
+ // TESTS_RANGE = new int[] { 16, -1 };
+}
+public static Test suite() {
+ return buildModelTestSuite(ResolveTests12.class);
+}
+public ResolveTests12(String name) {
+ super(name);
+}
+public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException {
+ return super.getWorkingCopy(path, source, this.wcOwner);
+}
+public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ setUpJavaProject("Resolve", "12", false);
+ waitUntilIndexesReady();
+}
+protected void setUp() throws Exception {
+ super.setUp();
+ this.wcOwner = new WorkingCopyOwner(){};
+}
+public void tearDownSuite() throws Exception {
+ deleteProject("Resolve");
+ super.tearDownSuite();
+}
+
+protected void tearDown() throws Exception {
+ if (this.wc != null) {
+ this.wc.discardWorkingCopy();
+ }
+ super.tearDown();
+}
+/*
+ * Multi constant case statement with ':', selection node is the string constant
+ */
+public void test001() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+
+ String str = this.wc.getSource();
+ String selection = "ONE";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "ONE [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with ':', selection node is the first enum constant
+ */
+public void test002() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "ONE";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "ONE [in Num [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with ':', selection node is the second string constant
+ */
+public void test003() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "TWO";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "TWO [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with ':', selection node is the second enum constant
+ */
+public void test004() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "TWO";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "TWO [in Num [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection node is the string constant
+ */
+public void test005() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "ONE";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "ONE [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection node is the first enum constant
+ */
+public void test006() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "ONE";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "ONE [in Num [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection node is the second string constant
+ */
+public void test007() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "TWO";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "TWO [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection node is the second enum constant
+ */
+public void test008() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "TWO";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "TWO [in Num [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * 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 {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(Num) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * 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 {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "i_j";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "i_j [in foo(Num) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type enum in switch expression
+ */
+public void test011() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(Num) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test012() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","public class X {\n" +
+ " public static void foo(int num_) {\n" +
+ " switch (num_ + 1) {\n" +
+ " case 1, 2, 3 -> {\n" +
+ " break;" +
+ " }\n" +
+ " }" +
+ " }\n" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test013() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test014() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test015() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "num_";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "num_ [in foo(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+/*
+ * Multi constant case statement with '->', selection is a referenced name of type int in switch expression
+ */
+public void test016() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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 str = this.wc.getSource();
+ String selection = "i_j";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "i_j [in bar(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+public void test017() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java","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 str = this.wc.getSource();
+ String selection = "i_j";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "i_j [in bar(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+public void test018() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java",
+ "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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "n_1";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "n_1() [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+public void test019() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java",
+ "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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "n_1";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "n_1() [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+public void test020() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java",
+ "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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "n_2";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "n_2() [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+public void test021() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java",
+ "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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "n_1";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "n_1(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]",
+ elements
+ );
+}
+public void test022() throws JavaModelException {
+ this.wc = getWorkingCopy("/Resolve/src/X.java",
+ "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" +
+ "}\n");
+ String str = this.wc.getSource();
+ String selection = "ijk";
+ int start = str.lastIndexOf(selection);
+ int length = selection.length();
+ IJavaElement[] elements = this.wc.codeSelect(start, length);
+ assertElementsEqual(
+ "Unexpected elements",
+ "ijk [in testSw(int) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
+ elements
+ );
+}
+}
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 dc7e1ac48e..348ad9ccb1 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
@@ -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
@@ -41,6 +41,7 @@ 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 433b8554ca..bd6a6e6a0f 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
@@ -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
@@ -3558,10 +3558,10 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
-
}
+ @SuppressWarnings("deprecation")
public void testSwitchStatement() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -3606,12 +3606,19 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
assertTrue("Number of statements not 0", statements.size() == 0);
SwitchCase caseStatement1= ast.newSwitchCase();
- caseStatement1.setExpression(ast.newNumberLiteral("1"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement1.setExpression(ast.newNumberLiteral("1"));
+ }
+ else {
+ caseStatement1.expressions().add(ast.newNumberLiteral("1"));
+ }
Statement statement1= ast.newReturnStatement();
SwitchCase caseStatement2= ast.newSwitchCase(); // default
- caseStatement2.setExpression(null);
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(null);
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
listRewrite.insertLast(caseStatement1, null);
@@ -3634,14 +3641,25 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
// change case statement
SwitchCase caseStatement= (SwitchCase) statements.get(3);
Expression newCaseExpression= ast.newNumberLiteral("10");
- rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
+ if (this.apiLevel < AST.JLS12) {
+ rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
+ } else {
+ List expressions = caseStatement.expressions();
+ ListRewrite listRewrite= rewrite.getListRewrite(caseStatement, SwitchCase.EXPRESSIONS2_PROPERTY);
+ listRewrite.replace((Expression)expressions.get(0), newCaseExpression, null);
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- caseStatement2.setExpression(ast.newNumberLiteral("11"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(ast.newNumberLiteral("11"));
+ }
+ else {
+ caseStatement2.expressions().add(ast.newNumberLiteral("11"));
+ }
listRewrite.insertFirst(caseStatement2, null);
// insert statement
@@ -3652,7 +3670,12 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- caseStatement2.setExpression(ast.newNumberLiteral("12"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(ast.newNumberLiteral("12"));
+ }
+ else {
+ caseStatement2.expressions().add(ast.newNumberLiteral("12"));
+ }
listRewrite.insertLast(caseStatement2, null);
// insert statement
@@ -3691,6 +3714,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
}
+ @SuppressWarnings("deprecation")
public void testSwitchStatement2() throws Exception {
String previousValue = null;
try {
@@ -3741,12 +3765,19 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
assertTrue("Number of statements not 0", statements.size() == 0);
SwitchCase caseStatement1= ast.newSwitchCase();
- caseStatement1.setExpression(ast.newNumberLiteral("1"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement1.setExpression(ast.newNumberLiteral("1"));
+ }
+ else {
+ caseStatement1.expressions().add(ast.newNumberLiteral("1"));
+ }
Statement statement1= ast.newReturnStatement();
SwitchCase caseStatement2= ast.newSwitchCase(); // default
- caseStatement2.setExpression(null);
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(null);
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
listRewrite.insertLast(caseStatement1, null);
@@ -3769,14 +3800,26 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
// change case statement
SwitchCase caseStatement= (SwitchCase) statements.get(3);
Expression newCaseExpression= ast.newNumberLiteral("10");
- rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
+ if (this.apiLevel < AST.JLS12) {
+ rewrite.replace(caseStatement.getExpression(), newCaseExpression, null);
+ } else {
+ List expressions = caseStatement.expressions();
+ ListRewrite listRewrite2= rewrite.getListRewrite(caseStatement, SwitchCase.EXPRESSIONS2_PROPERTY);
+ listRewrite2.replace((Expression)expressions.get(0), newCaseExpression, null);
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- caseStatement2.setExpression(ast.newNumberLiteral("11"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(ast.newNumberLiteral("11"));
+ }
+ else {
+ caseStatement2.expressions().add(ast.newNumberLiteral("11"));
+
+ }
listRewrite.insertFirst(caseStatement2, null);
// insert statement
@@ -3787,7 +3830,12 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
{
// insert case statement
SwitchCase caseStatement2= ast.newSwitchCase();
- caseStatement2.setExpression(ast.newNumberLiteral("12"));
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement2.setExpression(ast.newNumberLiteral("12"));
+ }
+ else {
+ caseStatement2.expressions().add(ast.newNumberLiteral("12"));
+ }
listRewrite.insertLast(caseStatement2, null);
// insert statement
@@ -4050,6 +4098,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=246627
* Replace a statement preceded by an unchanged statement)
*/
+ @SuppressWarnings("deprecation")
public void testSwitchStatement7() throws Exception {
String previousValue = null;
try {
@@ -4092,7 +4141,12 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
ExpressionStatement assignment = (ExpressionStatement)statements.get(1); // i= 1;:
SwitchCase switchCase = ast.newSwitchCase();
- switchCase.setExpression(ast.newNumberLiteral("2"));
+ if (this.apiLevel < AST.JLS12) {
+ switchCase.setExpression(ast.newNumberLiteral("2"));
+ }
+ else {
+ switchCase.expressions().add(ast.newNumberLiteral("2"));
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
listRewrite.replace(assignment, switchCase, null);
@@ -4192,6 +4246,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=246627
* Remove a statement followed by an inserted statement)
*/
+ @SuppressWarnings("deprecation")
public void testSwitchStatement9() throws Exception {
String previousValue = null;
try {
@@ -4234,7 +4289,12 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
ExpressionStatement assignment = (ExpressionStatement)statements.get(1); // i= 1;
SwitchCase switchCase = ast.newSwitchCase();
- switchCase.setExpression(ast.newNumberLiteral("2"));
+ if (this.apiLevel < AST.JLS12) {
+ switchCase.setExpression(ast.newNumberLiteral("2"));
+ }
+ else {
+ switchCase.expressions().add(ast.newNumberLiteral("2"));
+ }
ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
listRewrite.remove(assignment, null);
@@ -4513,6 +4573,151 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
}
}
}
+ @SuppressWarnings("deprecation")
+ public void testSwitchStatement_Bug543720() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = 0;\n"+
+ " switch (i) {\n"+
+ " case 1 : {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " default : {\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
+
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ if (this.apiLevel < AST.JLS12) {
+ caseStatement1.setExpression(ast.newNumberLiteral("100"));
+ } else {
+ caseStatement1.expressions().add(ast.newNumberLiteral("100"));
+ }
+
+ BreakStatement breakStatement = ast.newBreakStatement();
+ Block block1 = ast.newBlock();
+ block1.statements().add(breakStatement);
+
+ SwitchCase defaultCase = (SwitchCase) switchStmt.statements().get(2);
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStmt, SwitchStatement.STATEMENTS_PROPERTY);
+ listRewrite.insertBefore(caseStatement1, defaultCase, null);
+ listRewrite.insertBefore(block1, defaultCase, null);
+ }
+
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = 0;\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 : {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 100:\n");
+ buf.append(" {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ // complete removal of statements under switch statement.
+ public void testSwitchStatement_Bug543720_complete_removal() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = 0;\n"+
+ " switch (i) {\n"+
+ " case 1 : {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " default : {\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
+
+ List statements= switchStmt.statements();
+ for (int i = 0, l = statements.size(); i < l; ++i)
+ rewrite.remove((ASTNode) statements.get(i), null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = 0;\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" }\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
public void testSynchronizedStatement() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
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
new file mode 100644
index 0000000000..1303ab2207
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
@@ -0,0 +1,848 @@
+/*******************************************************************************
+ * 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.rewrite.describing;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BreakStatement;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+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.StringLiteral;
+import org.eclipse.jdt.core.dom.SwitchCase;
+import org.eclipse.jdt.core.dom.SwitchExpression;
+import org.eclipse.jdt.core.dom.SwitchStatement;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+
+import junit.framework.Test;
+
+public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
+
+
+ public ASTRewritingSwitchExpressionsTest(String name) {
+ super(name, 12);
+ }
+
+ public ASTRewritingSwitchExpressionsTest(String name, int apiLevel) {
+ super(name, apiLevel);
+ }
+
+ public static Test suite() {
+ return createSuite(ASTRewritingSwitchExpressionsTest.class);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testSwitchExpressions_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" }\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1, 2->\n");
+ buf.append(" i= 1;\n");
+ buf.append(" case 3->\n");
+ buf.append(" i= 3;\n");
+ buf.append(" default->\n");
+ buf.append(" i= 4;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 2", blockStatements.size() == 2);
+ { // insert statements, replace expression
+ SwitchStatement switchStatement= (SwitchStatement) blockStatements.get(0);
+
+ ASTNode expression= switchStatement.getExpression();
+ SimpleName newExpression= ast.newSimpleName("x");
+ rewrite.replace(expression, newExpression, null);
+
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 0", statements.size() == 0);
+
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ caseStatement1.setSwitchLabeledRule(true);
+ caseStatement1.expressions().add(ast.newNumberLiteral("1"));
+ caseStatement1.expressions().add(ast.newNumberLiteral("2"));
+
+
+ Statement statement1= ast.newReturnStatement();
+
+ SwitchCase caseStatement2= ast.newSwitchCase(); // default
+ caseStatement2.setSwitchLabeledRule(true);
+
+
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
+ listRewrite.insertAt(caseStatement1, 0, null);
+ listRewrite.insertLast(statement1, null);
+ listRewrite.insertLast(caseStatement2, null);
+ }
+
+ { // insert, remove, replace statements, change case statements
+ SwitchStatement switchStatement= (SwitchStatement) blockStatements.get(1);
+
+ List statements= switchStatement.statements();
+ assertTrue("Number of statements not 6", statements.size() == 6);
+
+ // remove statements
+
+ rewrite.remove((ASTNode) statements.get(0), null);
+ rewrite.remove((ASTNode) statements.get(1), null);
+
+ // change case statement
+ SwitchCase caseStatement= (SwitchCase) statements.get(2);
+ ListRewrite listRewrite= rewrite.getListRewrite(caseStatement, SwitchCase.EXPRESSIONS2_PROPERTY);
+
+ {
+ listRewrite.insertFirst(ast.newNumberLiteral("10"), null);
+ listRewrite.insertLast(ast.newNumberLiteral("12"), null);
+
+ }
+
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" switch (x) {\n");
+ buf.append(" case 1, 2->\n");
+ buf.append(" return;\n");
+ buf.append(" default->\n");
+ buf.append(" }\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 10, 3, 12->\n");
+ buf.append(" i= 3;\n");
+ buf.append(" default->\n");
+ buf.append(" i= 4;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ @SuppressWarnings("rawtypes")
+ 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");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1, 2->\n");
+ buf.append(" i= 1;\n");
+ buf.append(" case 3->\n");
+ buf.append(" i= 3;\n");
+ buf.append(" default->\n");
+ buf.append(" i= 4;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ SwitchStatement switchStatement= (SwitchStatement) blockStatements.get(0);
+
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ caseStatement1.setSwitchLabeledRule(true);
+ caseStatement1.expressions().add(ast.newNumberLiteral("1024"));
+
+ BreakStatement breakStatement = ast.newBreakStatement();
+ breakStatement.setExpression(ast.newNumberLiteral("2048"));
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
+
+ SwitchCase defaultCase = (SwitchCase) switchStatement.statements().get(4);
+ listRewrite.insertBefore(caseStatement1, defaultCase, null);
+ listRewrite.insertBefore(breakStatement, defaultCase, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1, 2->\n");
+ buf.append(" i= 1;\n");
+ buf.append(" case 3->\n");
+ buf.append(" i= 3;\n");
+ buf.append(" case 1024->\n");
+ buf.append(" break 2048;\n");
+ buf.append(" default->\n");
+ buf.append(" i= 4;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testSwitchExpressions_03_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = \n"+
+ " switch (i) {\n"+
+ " case 1 -> {\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";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ VariableDeclarationStatement stmt = (VariableDeclarationStatement) blockStatements.get(0);
+ SwitchExpression switchExpression= (SwitchExpression) ((VariableDeclarationFragment) stmt.fragments().get(0)).getInitializer();
+
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ caseStatement1.setSwitchLabeledRule(true);
+ caseStatement1.expressions().add(ast.newNumberLiteral("100"));
+ caseStatement1.expressions().add(ast.newNumberLiteral("200"));
+
+ SwitchCase caseStatement2= ast.newSwitchCase(); // default
+ caseStatement2.setSwitchLabeledRule(true);
+
+ BreakStatement breakStatement = ast.newBreakStatement();
+ breakStatement.setExpression(ast.newNumberLiteral("2048"));
+ Block block1 = ast.newBlock();
+ block1.statements().add(breakStatement);
+
+ SwitchCase defaultCase = (SwitchCase) switchExpression.statements().get(2);
+ ListRewrite listRewrite= rewrite.getListRewrite(switchExpression, SwitchExpression.STATEMENTS_PROPERTY);
+ listRewrite.insertBefore(caseStatement1, defaultCase, null);
+ listRewrite.insertBefore(block1, defaultCase, null);
+ }
+
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = \n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 -> {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break z;\n");
+ buf.append(" }\n");
+ buf.append(" case 100, 200->\n");
+ buf.append(" {\n");
+ buf.append(" break 2048;\n");
+ buf.append(" }\n");
+ buf.append(" default -> {\n");
+ buf.append(" break 12;\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void testSwitchStatement_Bug543720_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = 0;\n"+
+ " switch (i) {\n"+
+ " case 1 : {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " default : {\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
+
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ caseStatement1.expressions().add(ast.newNumberLiteral("100"));
+
+ BreakStatement breakStatement = ast.newBreakStatement();
+ Block block1 = ast.newBlock();
+ block1.statements().add(breakStatement);
+
+ SwitchCase defaultCase = (SwitchCase) switchStmt.statements().get(2);
+ ListRewrite listRewrite= rewrite.getListRewrite(switchStmt, SwitchStatement.STATEMENTS_PROPERTY);
+ listRewrite.insertBefore(caseStatement1, defaultCase, null);
+ listRewrite.insertBefore(block1, defaultCase, null);
+ }
+
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = 0;\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 : {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 100:\n");
+ buf.append(" {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ @SuppressWarnings("rawtypes")
+ 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"+
+ " 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";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // insert statements, replace expression
+ VariableDeclarationStatement stmt = (VariableDeclarationStatement) blockStatements.get(0);
+ SwitchExpression switchExpression= (SwitchExpression) ((VariableDeclarationFragment) stmt.fragments().get(0)).getInitializer();
+
+ ASTNode expression= switchExpression.getExpression();
+ SimpleName newExpression= ast.newSimpleName("x");
+ rewrite.replace(expression, newExpression, null);
+
+ List statements= switchExpression.statements();
+
+ // remove statements
+ rewrite.remove((ASTNode) statements.get(0), null);
+ rewrite.remove((ASTNode) statements.get(1), null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw =\n");
+ buf.append(" switch (x) {\n");
+ buf.append(" default -> {\n");
+ buf.append(" break 12;\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ //Note: complete removal of statements under switch statements now added in ASTRSTest and hence not repeated here.
+
+ // replacing colon by ->
+ @SuppressWarnings("rawtypes")
+ public void testSwitchStatement_Bug543720_05_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = 0;\n"+
+ " switch (i) {\n"+
+ " case 1 : {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " case 2 : {\n"+
+ " break;\n"+
+ " }\n"+
+ " default : {\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // set switch labeled rule
+ SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
+ for (int i = 0, l = switchStmt.statements().size(); i < l; ++i) {
+ Statement stmt = (Statement) switchStmt.statements().get(i);
+ if (stmt instanceof SwitchCase) {
+ SwitchCase switchCase = (SwitchCase) stmt;
+ assertTrue("Switch case has arrow", switchCase.isSwitchLabeledRule() == false);
+ rewrite.set(switchCase, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.TRUE, null);
+ }
+ }
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = 0;\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 -> {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 2 -> {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default -> {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ // replacing colon by ->
+ @SuppressWarnings("rawtypes")
+ public void testSwitchStatement_Bug543720_06_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw = 0;\n"+
+ " switch (i) {\n"+
+ " case 1 -> {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " case 2 -> {\n"+
+ " break;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " break;\n"+
+ " }\n"+
+ " }\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ { // set switch labeled rule
+ SwitchStatement switchStmt = (SwitchStatement) blockStatements.get(1);
+ for (int i = 0, l = switchStmt.statements().size(); i < l; ++i) {
+ Statement stmt = (Statement) switchStmt.statements().get(i);
+ if (stmt instanceof SwitchCase) {
+ SwitchCase switchCase = (SwitchCase) stmt;
+ assertTrue("Switch case has colon", switchCase.isSwitchLabeledRule() == true);
+ rewrite.set(switchCase, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.FALSE, null);
+ }
+ }
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw = 0;\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 : {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 2 : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ // replacing colon by ->
+ @SuppressWarnings("rawtypes")
+ public void testSwitchExpression_Bug543720_07_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw =\n"+
+ " switch (i) {\n"+
+ " case 1 : {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " case 2 : {\n"+
+ " break;\n"+
+ " }\n"+
+ " default : {\n"+
+ " break;\n"+
+ " }\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ {
+ VariableDeclarationStatement stmt = (VariableDeclarationStatement) blockStatements.get(0);
+ SwitchExpression switchExpression= (SwitchExpression) ((VariableDeclarationFragment) stmt.fragments().get(0)).getInitializer();
+ for (int i = 0, l = switchExpression.statements().size(); i < l; ++i) {
+ Statement stmt1 = (Statement) switchExpression.statements().get(i);
+ if (stmt1 instanceof SwitchCase) {
+ SwitchCase switchCase = (SwitchCase) stmt1;
+ assertTrue("Switch case has arrow", switchCase.isSwitchLabeledRule() == false);
+ rewrite.set(switchCase, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.TRUE, null);
+ }
+ }
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw =\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 -> {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 2 -> {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default -> {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ // replacing colon by ->
+ @SuppressWarnings("rawtypes")
+ public void testSwitchExpression_Bug543720_08_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String s =
+ "package test1;\n"+
+ "public class X {\n"+
+ " static int foo(int i) {\n"+
+ " int tw =\n"+
+ " switch (i) {\n"+
+ " case 1 -> {\n"+
+ " int z = 100;\n"+
+ " break;\n"+
+ " }\n"+
+ " case 2 -> {\n"+
+ " break;\n"+
+ " }\n"+
+ " default -> {\n"+
+ " break;\n"+
+ " }\n"+
+ " };\n"+
+ " return tw;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.print(foo(1));\n"+
+ " }\n"+
+ "}\n";
+ StringBuffer buf = new StringBuffer(s);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ {
+ VariableDeclarationStatement stmt = (VariableDeclarationStatement) blockStatements.get(0);
+ SwitchExpression switchExpression= (SwitchExpression) ((VariableDeclarationFragment) stmt.fragments().get(0)).getInitializer();
+ for (int i = 0, l = switchExpression.statements().size(); i < l; ++i) {
+ Statement stmt1 = (Statement) switchExpression.statements().get(i);
+ if (stmt1 instanceof SwitchCase) {
+ SwitchCase switchCase = (SwitchCase) stmt1;
+ assertTrue("Switch case has colon", switchCase.isSwitchLabeledRule() == true);
+ rewrite.set(switchCase, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.FALSE, null);
+ }
+ }
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class X {\n");
+ buf.append(" static int foo(int i) {\n");
+ buf.append(" int tw =\n");
+ buf.append(" switch (i) {\n");
+ buf.append(" case 1 : {\n");
+ buf.append(" int z = 100;\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" case 2 : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" default : {\n");
+ buf.append(" break;\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" return tw;\n");
+ buf.append(" }\n");
+ buf.append(" public static void main(String[] args) {\n");
+ buf.append(" System.out.print(foo(1));\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+ @SuppressWarnings("rawtypes")
+ public void testSwitchExpressions_05_since_12() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuilder builder= new StringBuilder();
+ builder.append("package test1;\n");
+ builder.append("public class X {\n");
+ builder.append(" public String foo(int i) {\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 -> \"even\";\n" +
+ " default -> \"\";\n" +
+ " };\n" +
+ " return ret;");
+ builder.append(" }\n");
+ builder.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", builder.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ AST ast= astRoot.getAST();
+ assertEquals("incorrect no of statements", 2, blockStatements.size());
+ { // insert a case
+ VariableDeclarationStatement varStatement= (VariableDeclarationStatement) blockStatements.get(0);
+ List fragments = varStatement.fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ SwitchExpression initializer = (SwitchExpression) fragment.getInitializer();
+ List statements= initializer.statements();
+ assertEquals("incorrect Number of statements", 4, statements.size());
+
+ SwitchCase cse1 = (SwitchCase) statements.get(0);
+ rewrite.set(cse1, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.FALSE, null);
+ SwitchCase cse2 = (SwitchCase) statements.get(2);
+ rewrite.set(cse2, SwitchCase.SWITCH_LABELED_RULE_PROPERTY, Boolean.FALSE, null);
+
+ ListRewrite listRewrite= rewrite.getListRewrite(initializer, SwitchExpression.STATEMENTS_PROPERTY);
+ SwitchCase caseStatement1= ast.newSwitchCase();
+ caseStatement1.setSwitchLabeledRule(false);
+ caseStatement1.expressions().add(ast.newNumberLiteral("1"));
+ StringLiteral literal1 = ast.newStringLiteral();
+ literal1.setLiteralValue("odd");
+ ExpressionStatement statement1 = ast.newExpressionStatement(literal1);
+ listRewrite.insertAt(caseStatement1, 2, null);
+ listRewrite.insertAt(statement1, 3, null);
+ }
+
+ // Expected output is not ideal due to formatting issue Bug 545439
+ String preview= evaluateRewrite(cu, rewrite);
+ builder= new StringBuilder();
+ builder.append("package test1;\n");
+ builder.append("public class X {\n");
+ builder.append(" public String foo(int i) {\n" +
+ " String ret = switch(i%2) {\n" +
+ " case 0 : \"even\";\n" +
+ " case 1:\n" +
+ " \"odd\";\n" +
+ " default : \"\";\n" +
+ " };\n" +
+ " return ret;");
+ builder.append(" }\n");
+ builder.append("}\n");
+ assertEqualString(preview, builder.toString());
+ }
+}
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 bf162e4e9c..5437dbb065 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
@@ -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,21 +16,33 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+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.rewrite.ASTRewrite;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests;
import org.eclipse.jface.text.Document;
import org.eclipse.text.edits.TextEdit;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
/**
* Tests for ASTRewrite. Subclasses must have 2 constructors that forward to
* constructors with the same signature as this class's constructors.
@@ -70,8 +82,10 @@ 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[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL };
+ private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS12_INTERNAL };
private static final String ONLY_AST_STRING = "_only";
private static final String SINCE_AST_STRING = "_since";
@@ -108,26 +122,31 @@ public class ASTRewritingTest extends AbstractJavaModelTests {
public static Test suite() {
TestSuite suite= new TestSuite(ASTRewritingTest.class.getName());
- suite.addTest(ASTRewritingExpressionsTest.suite());
- suite.addTest(ASTRewritingInsertBoundTest.suite());
- suite.addTest(ASTRewritingMethodDeclTest.suite());
- suite.addTest(ASTRewritingMoveCodeTest.suite());
- suite.addTest(ASTRewritingStatementsTest.suite());
- suite.addTest(ASTRewritingTrackingTest.suite());
- suite.addTest(ASTRewritingJavadocTest.suite());
- suite.addTest(ASTRewritingTypeAnnotationsTest.suite());
- suite.addTest(ASTRewritingTypeDeclTest.suite());
- suite.addTest(ASTRewritingGroupNodeTest.suite());
- suite.addTest(ASTRewritingRevertTest.suite());
- suite.addTest(LineCommentOffsetsTest.suite());
- suite.addTest(ASTRewritingWithStatementsRecoveryTest.suite());
- suite.addTest(ASTRewritePropertyTest.suite());
- suite.addTest(ASTRewritingPackageDeclTest.suite());
- suite.addTest(ASTRewritingLambdaExpressionTest.suite());
- suite.addTest(ASTRewritingReferenceExpressionTest.suite());
- suite.addTest(SourceModifierTest.suite());
- suite.addTest(ImportRewriteTest.suite());
- suite.addTest(ImportRewrite18Test.suite());
+
+
+ suite.addTest(ASTRewritingExpressionsTest.suite());
+ suite.addTest(ASTRewritingInsertBoundTest.suite());
+ suite.addTest(ASTRewritingMethodDeclTest.suite());
+ suite.addTest(ASTRewritingMoveCodeTest.suite());
+ suite.addTest(ASTRewritingStatementsTest.suite());
+ suite.addTest(ASTRewritingSwitchExpressionsTest.suite());
+
+ suite.addTest(ASTRewritingTrackingTest.suite());
+ suite.addTest(ASTRewritingJavadocTest.suite());
+ suite.addTest(ASTRewritin