langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java
author jjg
Fri, 02 May 2014 16:41:10 -0700
changeset 24292 12414a72f8d2
parent 17578 46ac954e4a84
child 24896 986d876a9121
permissions -rw-r--r--
8042358: some tests have placeholder bugid 1234567 Reviewed-by: mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     1
/*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     4
 *
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     8
 *
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    13
 * accompanied this code).
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    14
 *
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    18
 *
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    21
 * questions.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    22
 */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    23
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    24
import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    25
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    26
/*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    27
 * @test
24292
12414a72f8d2 8042358: some tests have placeholder bugid 1234567
jjg
parents: 17578
diff changeset
    28
 * @bug 8013852
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    29
 * @summary Test population of reference info for instance and class initializers
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    30
 * @author Werner Dietl
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    31
 * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    32
 * @run main Driver Initializers
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    33
 */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    34
public class Initializers {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    35
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    36
    @TADescriptions({
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    37
        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    38
        @TADescription(annotation = "TB", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    39
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    40
    })
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    41
    public String instanceInit1() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    42
        return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }";
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    43
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    44
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    45
    @TADescriptions({
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    46
        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    47
        @TADescription(annotation = "TB", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    48
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    49
        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    50
        @TADescription(annotation = "TD", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    51
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    52
    })
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    53
    public String instanceInit2() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    54
        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    55
                " { Object o = new @TC ArrayList<@TD String>(); } }";
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    56
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    57
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    58
    @TADescriptions({
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    59
        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    60
        @TADescription(annotation = "TB", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    61
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    62
    })
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    63
    public String staticInit1() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    64
        return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }";
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    65
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    66
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    67
    @TADescriptions({
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    68
        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    69
        @TADescription(annotation = "TB", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    70
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    71
        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    72
        @TADescription(annotation = "TD", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    73
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    74
        @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    75
        @TADescription(annotation = "TF", type = NEW,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    76
                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    77
    })
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    78
    public String staticInit2() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    79
        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    80
                " static Object g = new @TC ArrayList<@TD String>(); " +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    81
                " static { Object o = new @TE ArrayList<@TF String>(); } }";
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    82
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    83
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    84
    // TODO: test interaction with several constructors, especially non-initial constuctors.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    85
    // I don't think this kind of test is possible here.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    86
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    87
    @TADescriptions({
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    88
        @TADescription(annotation = "TA", type = CAST,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    89
                typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE),
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    90
    })
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    91
    public String lazyConstantCast1() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    92
        return "class Test { public static final Object o = (@TA Object) null; }";
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    93
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    94
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents:
diff changeset
    95
}