test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java

changeset 1521
71f35e4b93a5
child 1534
bec996065c45
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/TypeCasts.java	Wed Jan 23 13:27:24 2013 -0800
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright (c) 2009 Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
    1.28 +
    1.29 +/*
    1.30 + * @test
    1.31 + * @summary Test population of reference info for type casts
    1.32 + * @compile -g Driver.java ReferenceInfoUtil.java TypeCasts.java
    1.33 + * @run main Driver TypeCasts
    1.34 + */
    1.35 +public class TypeCasts {
    1.36 +
    1.37 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.38 +    public String returnObject() {
    1.39 +        return "Object returnObject() { return (@TA String)null; }";
    1.40 +    }
    1.41 +
    1.42 +    @TADescriptions({
    1.43 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.44 +        @TADescription(annotation = "TB", type = CAST,
    1.45 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.46 +        @TADescription(annotation = "TC", type = CAST,
    1.47 +                genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.48 +    })
    1.49 +    public String returnObjectArray() {
    1.50 +        return "Object returnObjectArray() { return (@TC String @TA [] @TB [])null; }";
    1.51 +    }
    1.52 +
    1.53 +    @TADescriptions({
    1.54 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.55 +        @TADescription(annotation = "TB", type = CAST,
    1.56 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.57 +    })
    1.58 +    public String returnObjectGeneric() {
    1.59 +        return "Object returnObjectGeneric() { return (@TA List<@TB String>)null; }";
    1.60 +    }
    1.61 +
    1.62 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.63 +    public String returnPrim() {
    1.64 +        return "Object returnPrim() { return (@TA int)0; }";
    1.65 +    }
    1.66 +
    1.67 +    @TADescriptions({
    1.68 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.69 +        @TADescription(annotation = "TB", type = CAST,
    1.70 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.71 +    })
    1.72 +    public String returnPrimArray() {
    1.73 +        return "Object returnPrimArray() { return (@TB int @TA [])null; }";
    1.74 +    }
    1.75 +
    1.76 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.77 +    public String initObject() {
    1.78 +        return "void initObject() { Object a =  (@TA String)null; }";
    1.79 +    }
    1.80 +
    1.81 +    @TADescriptions({
    1.82 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.83 +        @TADescription(annotation = "TB", type = CAST,
    1.84 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.85 +    })
    1.86 +    public String initObjectArray() {
    1.87 +        return "void initObjectArray() { Object a = (@TB String @TA [])null; }";
    1.88 +    }
    1.89 +
    1.90 +    @TADescriptions({
    1.91 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
    1.92 +        @TADescription(annotation = "TB", type = CAST,
    1.93 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    1.94 +    })
    1.95 +    public String initObjectGeneric() {
    1.96 +        return "void initObjectGeneric() { Object a = (@TA List<@TB String>)null; }";
    1.97 +    }
    1.98 +
    1.99 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.100 +    public String initPrim() {
   1.101 +        return "void initPrim() { Object a =  (@TA int)0; }";
   1.102 +    }
   1.103 +
   1.104 +    @TADescriptions({
   1.105 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
   1.106 +        @TADescription(annotation = "TB", type = CAST,
   1.107 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.108 +    })
   1.109 +    public String initPrimArray() {
   1.110 +        return "void initPrimArray() { Object a = (@TB int @TA [])null; }";
   1.111 +    }
   1.112 +
   1.113 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.114 +    public String eqtestObject() {
   1.115 +        return "void eqtestObject() { if (null == (@TA String)null); }";
   1.116 +    }
   1.117 +
   1.118 +    @TADescriptions({
   1.119 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
   1.120 +        @TADescription(annotation = "TB", type = CAST,
   1.121 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.122 +    })
   1.123 +    public String eqtestObjectArray() {
   1.124 +        return "void eqtestObjectArray() { if (null == (@TB String @TA [])null); }";
   1.125 +    }
   1.126 +
   1.127 +    @TADescriptions({
   1.128 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
   1.129 +        @TADescription(annotation = "TB", type = CAST,
   1.130 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.131 +    })
   1.132 +    public String eqtestObjectGeneric() {
   1.133 +        return "void eqtestObjectGeneric() { if (null == (@TA List<@TB String >)null); }";
   1.134 +    }
   1.135 +
   1.136 +    @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.137 +    // compiler optimizes away compile time constants casts
   1.138 +    public String eqtestPrim() {
   1.139 +        return "void eqtestPrim(int a) { if (0 == (@TA int)a); }";
   1.140 +    }
   1.141 +
   1.142 +    @TADescriptions({
   1.143 +        @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE),
   1.144 +        @TADescription(annotation = "TB", type = CAST,
   1.145 +                genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   1.146 +    })
   1.147 +    public String eqtestPrimArray() {
   1.148 +        return "void eqtestPrimArray() { if (null == (@TB int @TA [])null); }";
   1.149 +    }
   1.150 +
   1.151 +}

mercurial