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

Sun, 20 Oct 2013 12:46:12 -0700

author
jjg
date
Sun, 20 Oct 2013 12:46:12 -0700
changeset 2150
ae4f5cb78ebd
parent 0
959103a6100f
permissions
-rw-r--r--

8026791: wrong type_path encoded for method_return on an inner class constructor
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com

     1 /*
     2  * Copyright (c) 2013, 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  */
    24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
    26 /*
    27  * @test
    28  * @bug 1234567
    29  * @summary Test population of reference info for instance and class initializers
    30  * @author Werner Dietl
    31  * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java
    32  * @run main Driver Initializers
    33  */
    34 public class Initializers {
    36     @TADescriptions({
    37         @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    38         @TADescription(annotation = "TB", type = NEW,
    39                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    40     })
    41     public String instanceInit1() {
    42         return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }";
    43     }
    45     @TADescriptions({
    46         @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    47         @TADescription(annotation = "TB", type = NEW,
    48                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
    49         @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    50         @TADescription(annotation = "TD", type = NEW,
    51                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    52     })
    53     public String instanceInit2() {
    54         return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
    55                 " { Object o = new @TC ArrayList<@TD String>(); } }";
    56     }
    58     @TADescriptions({
    59         @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    60         @TADescription(annotation = "TB", type = NEW,
    61                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    62     })
    63     public String staticInit1() {
    64         return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }";
    65     }
    67     @TADescriptions({
    68         @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    69         @TADescription(annotation = "TB", type = NEW,
    70                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
    71         @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    72         @TADescription(annotation = "TD", type = NEW,
    73                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
    74         @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
    75         @TADescription(annotation = "TF", type = NEW,
    76                 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
    77     })
    78     public String staticInit2() {
    79         return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
    80                 " static Object g = new @TC ArrayList<@TD String>(); " +
    81                 " static { Object o = new @TE ArrayList<@TF String>(); } }";
    82     }
    84     // TODO: test interaction with several constructors, especially non-initial constuctors.
    85     // I don't think this kind of test is possible here.
    87     @TADescriptions({
    88         @TADescription(annotation = "TA", type = CAST,
    89                 typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE),
    90     })
    91     public String lazyConstantCast1() {
    92         return "class Test { public static final Object o = (@TA Object) null; }";
    93     }
    95 }

mercurial