0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 5027675 5048535
0N/A * @summary Tests FieldDeclaration.getConstantExpression method
0N/A * @library ../../lib
0N/A * @compile -source 1.5 ConstExpr.java
131N/A * @run main/othervm ConstExpr
0N/A */
0N/A
0N/A
0N/Aimport java.math.RoundingMode;
0N/Aimport java.util.*;
0N/A
0N/Aimport com.sun.mirror.declaration.*;
0N/Aimport com.sun.mirror.type.*;
0N/Aimport com.sun.mirror.util.*;
0N/A
0N/Aimport static java.math.RoundingMode.UP;
0N/A
0N/Aimport static com.sun.mirror.util.DeclarationVisitors.*;
0N/A
0N/A
0N/Apublic class ConstExpr extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new ConstExpr()).run();
0N/A }
0N/A
0N/A
0N/A // Declarations used by tests
0N/A
0N/A public static final byte B = (byte) 0xBE;
0N/A public static final short S = (short) 32767;
0N/A public static final int I = -4;
0N/A public static final long l = 4294967296L;
0N/A public static final float f = 3.5f;
0N/A public static final double PI = Math.PI;
0N/A public static final char C = 'C';
0N/A public static final String STR = "cheese";
0N/A
0N/A public static final char SMILEY = '\u263A';
0N/A public static final String TWOLINES = "ab\ncd";
0N/A
0N/A public static final double D1 = Double.POSITIVE_INFINITY;
0N/A public static final double D2 = Double.NEGATIVE_INFINITY;
0N/A public static final double D3 = Double.NaN;
0N/A public static final float F1 = Float.POSITIVE_INFINITY;
0N/A public static final float F2 = Float.NEGATIVE_INFINITY;
0N/A public static final float F3 = Float.NaN;
0N/A
0N/A public static final String NOSTR = null; // not a compile-time constant
0N/A public static final RoundingMode R = UP; // not a compile-time constant
0N/A
0N/A
0N/A @Test(result={
0N/A "0xbe",
0N/A "32767",
0N/A "-4",
0N/A "4294967296L",
0N/A "3.5f",
0N/A "3.141592653589793",
0N/A "'C'",
0N/A "\"cheese\"",
0N/A
0N/A "'\\u263a'",
0N/A "\"ab\\ncd\"",
0N/A
0N/A "1.0/0.0",
0N/A "-1.0/0.0",
0N/A "0.0/0.0",
0N/A "1.0f/0.0f",
0N/A "-1.0f/0.0f",
0N/A "0.0f/0.0f",
0N/A
0N/A "null",
0N/A "null"
0N/A },
0N/A ordered=true)
0N/A Collection<String> getConstantExpression() {
0N/A final Collection<String> res = new ArrayList<String>();
0N/A
0N/A thisClassDecl.accept(
0N/A DeclarationVisitors.getSourceOrderDeclarationScanner(
0N/A NO_OP,
0N/A new SimpleDeclarationVisitor() {
0N/A public void visitFieldDeclaration(FieldDeclaration f) {
0N/A res.add(f.getConstantExpression());
0N/A }
0N/A }));
0N/A return res;
0N/A }
0N/A}