test/tools/javac/tree/MakeLiteralTest.java

changeset 1374
c002fdee76fd
parent 788
8ec3a824f925
child 2525
2eb010b6cb22
equal deleted inserted replaced
1373:4a1c57a1c410 1374:c002fdee76fd
1
2
3 /* 1 /*
4 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * 4 *
7 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
28 * @bug 6504896 26 * @bug 6504896
29 * @summary TreeMaker.Literal(Object) does not support Booleans 27 * @summary TreeMaker.Literal(Object) does not support Booleans
30 */ 28 */
31 29
32 import com.sun.tools.javac.code.Type; 30 import com.sun.tools.javac.code.Type;
31 import com.sun.tools.javac.code.TypeTag;
33 import com.sun.tools.javac.code.Symtab; 32 import com.sun.tools.javac.code.Symtab;
34 import com.sun.tools.javac.code.Types; 33 import com.sun.tools.javac.code.Types;
35 import com.sun.tools.javac.file.JavacFileManager; 34 import com.sun.tools.javac.file.JavacFileManager;
36 import com.sun.tools.javac.tree.JCTree.JCLiteral; 35 import com.sun.tools.javac.tree.JCTree.JCLiteral;
37 import com.sun.tools.javac.util.Context; 36 import com.sun.tools.javac.util.Context;
38 import com.sun.tools.javac.tree.TreeMaker; 37 import com.sun.tools.javac.tree.TreeMaker;
39 import static com.sun.tools.javac.code.TypeTags.*; 38 import static com.sun.tools.javac.code.TypeTag.*;
40 39
41 public class MakeLiteralTest { 40 public class MakeLiteralTest {
42 public static void main(String... args) throws Exception { 41 public static void main(String... args) throws Exception {
43 new MakeLiteralTest().run(); 42 new MakeLiteralTest().run();
44 } 43 }
63 62
64 if (errors > 0) 63 if (errors > 0)
65 throw new Exception(errors + " errors found"); 64 throw new Exception(errors + " errors found");
66 } 65 }
67 66
68 void test(Object value, int tag, Type type, Object constValue) { 67 void test(Object value, TypeTag tag, Type type, Object constValue) {
69 JCLiteral l = maker.Literal(value); 68 JCLiteral l = maker.Literal(value);
70 if (l.type.tag != tag) 69 if (!l.type.hasTag(tag))
71 error("unexpected tag: " + l.getTag() + ": expected: " + tag); 70 error("unexpected tag: " + l.getTag() + ": expected: " + tag);
72 if (!types.isSameType(l.type, type)) 71 if (!types.isSameType(l.type, type))
73 error("unexpected type: " + l.type + ": expected: " + type); 72 error("unexpected type: " + l.type + ": expected: " + type);
74 if (l.type.constValue().getClass() != constValue.getClass() 73 if (l.type.constValue().getClass() != constValue.getClass()
75 || !constValue.equals(l.type.constValue())) { 74 || !constValue.equals(l.type.constValue())) {

mercurial