1
+ /*
2
+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
+ *
5
+ * This code is free software; you can redistribute it and/or modify it
6
+ * under the terms of the GNU General Public License version 2 only, as
7
+ * published by the Free Software Foundation.
8
+ *
9
+ * This code is distributed in the hope that it will be useful, but WITHOUT
10
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
+ * version 2 for more details (a copy is included in the LICENSE file that
13
+ * accompanied this code).
14
+ *
15
+ * You should have received a copy of the GNU General Public License version
16
+ * 2 along with this work; if not, write to the Free Software Foundation,
17
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ *
19
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
+ * or visit www.oracle.com if you need additional information or have any
21
+ * questions.
22
+ */
23
+ /**
24
+ * @test
25
+ * @bug 8314275
26
+ * @summary Tests a line number table attribute for switch expression
27
+ * @library /tools/lib /tools/javac/lib ../lib
28
+ * @enablePreview
29
+ * @modules jdk.compiler/com.sun.tools.javac.api
30
+ * jdk.compiler/com.sun.tools.javac.main
31
+ * jdk.compiler/com.sun.tools.javac.util
32
+ * java.base/jdk.internal.classfile.impl
33
+ * @build toolbox.ToolBox InMemoryFileManager TestBase
34
+ * @build LineNumberTestBase TestCase
35
+ * @run main T8314275
36
+ */
37
+ import java .util .List ;
38
+ public class T8314275 extends LineNumberTestBase {
39
+ public static void main (String [] args ) throws Exception {
40
+ new T8314275 ().test ();
41
+ }
42
+
43
+ public void test () throws Exception {
44
+ test (List .of (TEST_CASE ));
45
+ }
46
+
47
+ private static final TestCase [] TEST_CASE = new TestCase [] {
48
+ new TestCase ("""
49
+ public class T8314275Expression { // 1
50
+ private static double multiply(Integer i) { // 2
51
+ double cr = 15; // 3
52
+ cr = switch (i) { // 4
53
+ case 1 -> cr * 1; // 5
54
+ case 2 -> cr * 2; // 6
55
+ default -> cr * 4; // 7
56
+ }; // 8
57
+ return cr; // 9
58
+ } //10
59
+ } //11
60
+ """ ,
61
+ List .of (1 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ),
62
+ "T8314275Expression" ),
63
+ new TestCase ("""
64
+ public class T8314275Statement { // 1
65
+ private static double multiply(Integer i) { // 2
66
+ double cr = 15; // 3
67
+ switch (i) { // 4
68
+ case 1: cr *= 1; break; // 5
69
+ case 2: cr *= 2; break; // 6
70
+ default: cr *= 4; // 7
71
+ }; // 8
72
+ return cr; // 9
73
+ } //10
74
+ } //11
75
+ """ ,
76
+ List .of (1 , 3 , 4 , 5 , 6 , 7 , 9 ),
77
+ "T8314275Statement" )
78
+ };
79
+ }
1 commit comments
openjdk-notifier[bot] commentedon Feb 15, 2024
Review
Issues