author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 23391 | 3425f886b641 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
23391
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
1 |
/* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
4 |
* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
8 |
* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
13 |
* accompanied this code). |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
14 |
* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
18 |
* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
21 |
* questions. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
22 |
*/ |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
23 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
24 |
/* |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
25 |
* @test |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
26 |
* @bug 8034091 |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
27 |
* @summary Add LineNumberTable attributes for conditional operator (?:) split across several lines. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
28 |
*/ |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
29 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
30 |
import com.sun.tools.classfile.ClassFile; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
31 |
import com.sun.tools.classfile.ConstantPoolException; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
32 |
import com.sun.tools.classfile.Method; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.Attribute; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.Code_attribute; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.LineNumberTable_attribute; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.LineNumberTable_attribute.Entry; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
37 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
38 |
import java.io.File; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
39 |
import java.io.IOException; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
40 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
41 |
public class ConditionalLineNumberTest { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
42 |
public static void main(String[] args) throws Exception { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
43 |
// check that we have 5 consecutive entries for method() |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
44 |
Entry[] lines = findEntries(); |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
45 |
if (lines == null || lines.length != 5) |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
46 |
throw new Exception("conditional line number table incorrect"); |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
47 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
48 |
int current = lines[0].line_number; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
49 |
for (Entry e : lines) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
50 |
if (e.line_number != current) |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
51 |
throw new Exception("conditional line number table incorrect"); |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
52 |
current++; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
53 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
54 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
55 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
56 |
static Entry[] findEntries() throws IOException, ConstantPoolException { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
57 |
ClassFile self = ClassFile.read(ConditionalLineNumberTest.class.getResourceAsStream("ConditionalLineNumberTest.class")); |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
58 |
for (Method m : self.methods) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
59 |
if ("method".equals(m.getName(self.constant_pool))) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
60 |
Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code); |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
61 |
for (Attribute at : code_attribute.attributes) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
62 |
if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
63 |
return ((LineNumberTable_attribute)at).line_number_table; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
64 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
65 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
66 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
67 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
68 |
return null; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
69 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
70 |
|
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
71 |
// This method should get one LineNumberTable entry per line |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
72 |
// in the method body. |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
73 |
public static String method(int field) { |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
74 |
String s = field % 2 == 0 ? |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
75 |
(field == 0 ? "false" |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
76 |
: "true" + field) : //Breakpoint |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
77 |
"false" + field; //Breakpoint |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
78 |
return s; |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
79 |
} |
3425f886b641
8034091: There is no records in LineNumberTable attribute for ternary operator ?: splitted to several lines.
pgovereau
parents:
diff
changeset
|
80 |
} |