test/tools/apt/mirror/declaration/ConstExpr.java

changeset 1
9a66ca7c79fa
child 132
a54ef8459576
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/apt/mirror/declaration/ConstExpr.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 + * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +
    1.28 +/*
    1.29 + * @test
    1.30 + * @bug 5027675 5048535
    1.31 + * @summary Tests FieldDeclaration.getConstantExpression method
    1.32 + * @library ../../lib
    1.33 + * @compile -source 1.5 ConstExpr.java
    1.34 + * @run main ConstExpr
    1.35 + */
    1.36 +
    1.37 +
    1.38 +import java.math.RoundingMode;
    1.39 +import java.util.*;
    1.40 +
    1.41 +import com.sun.mirror.declaration.*;
    1.42 +import com.sun.mirror.type.*;
    1.43 +import com.sun.mirror.util.*;
    1.44 +
    1.45 +import static java.math.RoundingMode.UP;
    1.46 +
    1.47 +import static com.sun.mirror.util.DeclarationVisitors.*;
    1.48 +
    1.49 +
    1.50 +public class ConstExpr extends Tester {
    1.51 +
    1.52 +    public static void main(String[] args) {
    1.53 +        (new ConstExpr()).run();
    1.54 +    }
    1.55 +
    1.56 +
    1.57 +    // Declarations used by tests
    1.58 +
    1.59 +    public static final byte B = (byte) 0xBE;
    1.60 +    public static final short S = (short) 32767;
    1.61 +    public static final int I = -4;
    1.62 +    public static final long l = 4294967296L;
    1.63 +    public static final float f = 3.5f;
    1.64 +    public static final double PI = Math.PI;
    1.65 +    public static final char C = 'C';
    1.66 +    public static final String STR = "cheese";
    1.67 +
    1.68 +    public static final char SMILEY = '\u263A';
    1.69 +    public static final String TWOLINES = "ab\ncd";
    1.70 +
    1.71 +    public static final double D1 = Double.POSITIVE_INFINITY;
    1.72 +    public static final double D2 = Double.NEGATIVE_INFINITY;
    1.73 +    public static final double D3 = Double.NaN;
    1.74 +    public static final float  F1 = Float.POSITIVE_INFINITY;
    1.75 +    public static final float  F2 = Float.NEGATIVE_INFINITY;
    1.76 +    public static final float  F3 = Float.NaN;
    1.77 +
    1.78 +    public static final String NOSTR = null;    // not a compile-time constant
    1.79 +    public static final RoundingMode R = UP;    // not a compile-time constant
    1.80 +
    1.81 +
    1.82 +    @Test(result={
    1.83 +              "0xbe",
    1.84 +              "32767",
    1.85 +              "-4",
    1.86 +              "4294967296L",
    1.87 +              "3.5f",
    1.88 +              "3.141592653589793",
    1.89 +              "'C'",
    1.90 +              "\"cheese\"",
    1.91 +
    1.92 +              "'\\u263a'",
    1.93 +              "\"ab\\ncd\"",
    1.94 +
    1.95 +              "1.0/0.0",
    1.96 +              "-1.0/0.0",
    1.97 +              "0.0/0.0",
    1.98 +              "1.0f/0.0f",
    1.99 +              "-1.0f/0.0f",
   1.100 +              "0.0f/0.0f",
   1.101 +
   1.102 +              "null",
   1.103 +              "null"
   1.104 +          },
   1.105 +          ordered=true)
   1.106 +    Collection<String> getConstantExpression() {
   1.107 +        final Collection<String> res = new ArrayList<String>();
   1.108 +
   1.109 +        thisClassDecl.accept(
   1.110 +            DeclarationVisitors.getSourceOrderDeclarationScanner(
   1.111 +                NO_OP,
   1.112 +                new SimpleDeclarationVisitor() {
   1.113 +                    public void visitFieldDeclaration(FieldDeclaration f) {
   1.114 +                        res.add(f.getConstantExpression());
   1.115 +                    }
   1.116 +                }));
   1.117 +        return res;
   1.118 +    }
   1.119 +}

mercurial