1/*
2 * Copyright (c) 2002, 2015, 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/*
25 * @test
26 * @bug 4587494
27 * @summary Constant field values for boolean Data-Types don't use true and false
28 * @author gafter
29 * @modules jdk.javadoc
30 * @run main BooleanConst
31 */
32
33import com.sun.javadoc.*;
34import java.util.*;
35
36public class BooleanConst extends Doclet
37{
38    public static void main(String[] args) {
39        // run javadoc on package p
40        if (com.sun.tools.javadoc.Main.
41            execute("javadoc", "BooleanConst", BooleanConst.class.getClassLoader(),
42                    new String[] {System.getProperty("test.src", ".") + java.io.File.separatorChar + "BooleanConst.java"}) != 0)
43            throw new Error();
44    }
45
46    public static final boolean b1 = false;
47    public static final boolean b2 = true;
48
49    public static boolean start(com.sun.javadoc.RootDoc root) {
50        ClassDoc[] classes = root.classes();
51        if (classes.length != 1)
52            throw new Error("1 " + Arrays.asList(classes));
53        ClassDoc self = classes[0];
54        FieldDoc[] fields = self.fields();
55        if (fields.length != 2)
56            throw new Error("2 " + Arrays.asList(fields));
57        for (int i=0; i<fields.length; i++) {
58            FieldDoc f = fields[i];
59            if (f.name().equals("b1")) {
60                Object value = f.constantValue();
61                if (value == null || !(value instanceof Boolean) || ((Boolean)value).booleanValue())
62                    throw new Error("4 " + value);
63            } else if (f.name().equals("b2")) {
64                Object value = f.constantValue();
65                if (value == null || !(value instanceof Boolean) || !((Boolean)value).booleanValue())
66                    throw new Error("5 " + value);
67            } else throw new Error("3 " + f.name());
68        }
69        return true;
70    }
71}
72