author | ysuenaga |
Wed, 30 Mar 2016 21:05:13 +0900 | |
changeset 37218 | c7241bc368bf |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22154
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
4 |
* |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
8 |
* |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
14 |
* |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
18 |
* |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
21 |
* questions. |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
22 |
*/ |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
23 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
24 |
/* |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
25 |
* @test |
22154
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
26 |
* @bug 6504896 8028415 |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
27 |
* @summary TreeMaker.Literal(Object) does not support Booleans |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22154
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22154
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22154
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.tree |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22154
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.util |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
32 |
*/ |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
33 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.code.Type; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
7636
diff
changeset
|
35 |
import com.sun.tools.javac.code.TypeTag; |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symtab; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Types; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.file.JavacFileManager; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.tree.JCTree.JCLiteral; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.util.Context; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.tree.TreeMaker; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
7636
diff
changeset
|
42 |
import static com.sun.tools.javac.code.TypeTag.*; |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
43 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
44 |
public class MakeLiteralTest { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
45 |
public static void main(String... args) throws Exception { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
46 |
new MakeLiteralTest().run(); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
47 |
} |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
48 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
49 |
void run() throws Exception { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
50 |
Context context = new Context(); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
51 |
JavacFileManager.preRegister(context); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
52 |
Symtab syms = Symtab.instance(context); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
53 |
maker = TreeMaker.instance(context); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
54 |
types = Types.instance(context); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
55 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
56 |
test("abc", CLASS, syms.stringType, "abc"); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
57 |
test(Boolean.FALSE, BOOLEAN, syms.booleanType, Integer.valueOf(0)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
58 |
test(Boolean.TRUE, BOOLEAN, syms.booleanType, Integer.valueOf(1)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
59 |
test(Byte.valueOf((byte) 1), BYTE, syms.byteType, Byte.valueOf((byte) 1)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
60 |
test(Character.valueOf('a'), CHAR, syms.charType, Integer.valueOf('a')); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
61 |
test(Double.valueOf(1d), DOUBLE, syms.doubleType, Double.valueOf(1d)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
62 |
test(Float.valueOf(1f), FLOAT, syms.floatType, Float.valueOf(1f)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
63 |
test(Integer.valueOf(1), INT, syms.intType, Integer.valueOf(1)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
64 |
test(Long.valueOf(1), LONG, syms.longType, Long.valueOf(1)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
65 |
test(Short.valueOf((short) 1), SHORT, syms.shortType, Short.valueOf((short) 1)); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
66 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
67 |
if (errors > 0) |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
68 |
throw new Exception(errors + " errors found"); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
69 |
} |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
70 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
7636
diff
changeset
|
71 |
void test(Object value, TypeTag tag, Type type, Object constValue) { |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
72 |
JCLiteral l = maker.Literal(value); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
7636
diff
changeset
|
73 |
if (!l.type.hasTag(tag)) |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
74 |
error("unexpected tag: " + l.getTag() + ": expected: " + tag); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
75 |
if (!types.isSameType(l.type, type)) |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
76 |
error("unexpected type: " + l.type + ": expected: " + type); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
77 |
if (l.type.constValue().getClass() != constValue.getClass() |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
78 |
|| !constValue.equals(l.type.constValue())) { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
79 |
error("unexpected const value: " |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
80 |
+ l.type.constValue().getClass() + " " + l.type.constValue() |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
81 |
+ ": expected:" + constValue.getClass() + " " + constValue); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
82 |
} |
22154
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
83 |
if (l.getValue().getClass() != value.getClass() |
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
84 |
|| !value.equals(l.getValue())) { |
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
85 |
error("unexpected const value: " |
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
86 |
+ l.getValue().getClass() + " " + l.type.constValue() |
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
87 |
+ ": expected:" + value.getClass() + " " + value); |
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
14359
diff
changeset
|
88 |
} |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
89 |
} |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
90 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
91 |
void error(String msg) { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
92 |
System.err.println("Error: " + msg); |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
93 |
errors++; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
94 |
} |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
95 |
|
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
96 |
TreeMaker maker; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
97 |
Types types; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
98 |
int errors; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
diff
changeset
|
99 |
} |