787N/A
787N/A
787N/A/*
787N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
787N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
787N/A *
787N/A * This code is free software; you can redistribute it and/or modify it
787N/A * under the terms of the GNU General Public License version 2 only, as
787N/A * published by the Free Software Foundation.
787N/A *
787N/A * This code is distributed in the hope that it will be useful, but WITHOUT
787N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
787N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
787N/A * version 2 for more details (a copy is included in the LICENSE file that
787N/A * accompanied this code).
787N/A *
787N/A * You should have received a copy of the GNU General Public License version
787N/A * 2 along with this work; if not, write to the Free Software Foundation,
787N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
787N/A *
787N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
787N/A * or visit www.oracle.com if you need additional information or have any
787N/A * questions.
787N/A */
787N/A
787N/A/*
787N/A * @test
787N/A * @bug 6504896
787N/A * @summary TreeMaker.Literal(Object) does not support Booleans
787N/A */
787N/A
787N/Aimport com.sun.tools.javac.code.Type;
787N/Aimport com.sun.tools.javac.code.Symtab;
787N/Aimport com.sun.tools.javac.code.Types;
787N/Aimport com.sun.tools.javac.file.JavacFileManager;
787N/Aimport com.sun.tools.javac.tree.JCTree.JCLiteral;
787N/Aimport com.sun.tools.javac.util.Context;
787N/Aimport com.sun.tools.javac.tree.TreeMaker;
787N/Aimport static com.sun.tools.javac.code.TypeTags.*;
787N/A
787N/Apublic class MakeLiteralTest {
787N/A public static void main(String... args) throws Exception {
787N/A new MakeLiteralTest().run();
787N/A }
787N/A
787N/A void run() throws Exception {
787N/A Context context = new Context();
787N/A JavacFileManager.preRegister(context);
787N/A Symtab syms = Symtab.instance(context);
787N/A maker = TreeMaker.instance(context);
787N/A types = Types.instance(context);
787N/A
787N/A test("abc", CLASS, syms.stringType, "abc");
787N/A test(Boolean.FALSE, BOOLEAN, syms.booleanType, Integer.valueOf(0));
787N/A test(Boolean.TRUE, BOOLEAN, syms.booleanType, Integer.valueOf(1));
787N/A test(Byte.valueOf((byte) 1), BYTE, syms.byteType, Byte.valueOf((byte) 1));
787N/A test(Character.valueOf('a'), CHAR, syms.charType, Integer.valueOf('a'));
787N/A test(Double.valueOf(1d), DOUBLE, syms.doubleType, Double.valueOf(1d));
787N/A test(Float.valueOf(1f), FLOAT, syms.floatType, Float.valueOf(1f));
787N/A test(Integer.valueOf(1), INT, syms.intType, Integer.valueOf(1));
787N/A test(Long.valueOf(1), LONG, syms.longType, Long.valueOf(1));
787N/A test(Short.valueOf((short) 1), SHORT, syms.shortType, Short.valueOf((short) 1));
787N/A
787N/A if (errors > 0)
787N/A throw new Exception(errors + " errors found");
787N/A }
787N/A
787N/A void test(Object value, int tag, Type type, Object constValue) {
787N/A JCLiteral l = maker.Literal(value);
787N/A if (l.type.tag != tag)
787N/A error("unexpected tag: " + l.getTag() + ": expected: " + tag);
787N/A if (!types.isSameType(l.type, type))
787N/A error("unexpected type: " + l.type + ": expected: " + type);
787N/A if (l.type.constValue().getClass() != constValue.getClass()
787N/A || !constValue.equals(l.type.constValue())) {
787N/A error("unexpected const value: "
787N/A + l.type.constValue().getClass() + " " + l.type.constValue()
787N/A + ": expected:" + constValue.getClass() + " " + constValue);
787N/A }
787N/A }
787N/A
787N/A void error(String msg) {
787N/A System.err.println("Error: " + msg);
787N/A errors++;
787N/A }
787N/A
787N/A TreeMaker maker;
787N/A Types types;
787N/A int errors;
787N/A}