test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 24895 langtools/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java@dd091d389fbf
child 59285 7799a51dbe30
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     1
/*
23393
1698e8b53501 8036842: Remove unneeded/obsolete -source/-target options in javac tests, part 2
darcy
parents: 21041
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     4
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     8
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    13
 * accompanied this code).
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    14
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    18
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    21
 * questions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    22
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    23
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    24
import java.lang.annotation.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    25
import java.io.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    26
import java.net.URL;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    27
import java.util.List;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    28
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    29
import com.sun.tools.classfile.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    30
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    31
public class ClassfileTestHelper {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    32
    int expected_tinvisibles = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    33
    int expected_tvisibles = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    34
    int expected_invisibles = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    35
    int expected_visibles = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    36
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    37
    //Makes debugging much easier. Set to 'false' for less output.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    38
    public Boolean verbose = true;
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23393
diff changeset
    39
    void println(String msg) { if (verbose) System.err.println(msg); }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23393
diff changeset
    40
    void print(String msg) { if (verbose) System.err.print(msg); }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    41
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    42
    File writeTestFile(String fname, String source) throws IOException {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    43
      File f = new File(fname);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    44
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    45
        out.println(source);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    46
        out.close();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    47
        return f;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    48
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    49
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    50
    File compile(File f) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    51
        int rc = com.sun.tools.javac.Main.compile(new String[] {
23393
1698e8b53501 8036842: Remove unneeded/obsolete -source/-target options in javac tests, part 2
darcy
parents: 21041
diff changeset
    52
                "-g", f.getPath() });
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    53
        if (rc != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    54
            throw new Error("compilation failed. rc=" + rc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    55
        String path = f.getPath();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    56
        return new File(path.substring(0, path.length() - 5) + ".class");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    57
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    58
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    59
    ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    60
        URL url = getClass().getResource(name);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    61
        InputStream in = url.openStream();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    62
        try {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    63
            return ClassFile.read(in);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    64
        } finally {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    65
            in.close();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    66
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    67
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    68
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    69
    ClassFile getClassFile(URL url) throws IOException, ConstantPoolException {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    70
        InputStream in = url.openStream();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    71
        try {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    72
            return ClassFile.read(in);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    73
        } finally {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    74
            in.close();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    75
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    76
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    77
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    78
    /************ Helper annotations counting methods ******************/
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    79
    void test(ClassFile cf) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    80
        test("CLASS",cf, null, null, Attribute.RuntimeVisibleTypeAnnotations, true);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    81
        test("CLASS",cf, null, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    82
        //RuntimeAnnotations since one annotation can result in two attributes.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    83
        test("CLASS",cf, null, null, Attribute.RuntimeVisibleAnnotations, true);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    84
        test("CLASS",cf, null, null, Attribute.RuntimeInvisibleAnnotations, false);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    85
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    86
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    87
    void test(ClassFile cf, Field f, Boolean local) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    88
        if (!local) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    89
            test("FIELD",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    90
            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    91
            test("FIELD",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    92
            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    93
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    94
            test("CODE",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    95
            test("CODE",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    96
            test("CODE",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    97
            test("CODE",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
    98
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    99
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   100
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   101
    void test(ClassFile cf, Field f) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   102
        test(cf, f, false);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   103
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   104
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   105
    // 'local' determines whether to look for annotations in code attribute or not.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   106
    void test(ClassFile cf, Method m, Boolean local) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   107
        if (!local) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   108
            test("METHOD",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   109
            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   110
            test("METHOD",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   111
            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   112
        } else  {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   113
            test("MCODE",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   114
            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   115
            test("MCODE",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   116
            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   117
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   118
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   119
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   120
    // default to not looking in code attribute
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   121
    void test(ClassFile cf, Method m ) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   122
        test(cf, m, false);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   123
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   124
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   125
    // Test the result of Attributes.getIndex according to expectations
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   126
    // encoded in the class/field/method name; increment annotations counts.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   127
    void test(String ttype, ClassFile cf, Field f, Method m, String annName, boolean visible) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   128
        String testtype = ttype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   129
        String name = null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   130
        int index = -1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   131
        Attribute attr = null;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   132
        Code_attribute cAttr = null;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   133
        boolean isTAattr = annName.contains("TypeAnnotations");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   134
        try {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   135
            switch(testtype) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   136
                case "FIELD":
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   137
                    name = f.getName(cf.constant_pool);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   138
                    index = f.attributes.getIndex(cf.constant_pool, annName);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   139
                    if(index!= -1)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   140
                        attr = f.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   141
                    break;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   142
                case "CODE":
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   143
                    name = f.getName(cf.constant_pool);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   144
                    //fetch index of and code attribute and annotations from code attribute.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   145
                    index = cf.attributes.getIndex(cf.constant_pool, Attribute.Code);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   146
                    if(index!= -1) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   147
                        attr = cf.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   148
                        assert attr instanceof Code_attribute;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   149
                        cAttr = (Code_attribute)attr;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   150
                        index = cAttr.attributes.getIndex(cf.constant_pool, annName);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   151
                        if(index!= -1)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   152
                            attr = cAttr.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   153
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   154
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   155
                case "METHOD":
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   156
                    name = m.getName(cf.constant_pool);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   157
                    index = m.attributes.getIndex(cf.constant_pool, annName);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   158
                    if(index!= -1)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   159
                        attr = m.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   160
                    break;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   161
                case "MCODE":
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   162
                    name = m.getName(cf.constant_pool);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   163
                    //fetch index of and code attribute and annotations from code attribute.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   164
                    index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   165
                    if(index!= -1) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   166
                        attr = m.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   167
                        assert attr instanceof Code_attribute;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   168
                        cAttr = (Code_attribute)attr;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   169
                        index = cAttr.attributes.getIndex(cf.constant_pool, annName);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   170
                        if(index!= -1)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   171
                            attr = cAttr.attributes.get(index);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   172
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   173
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   174
                default:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   175
                    name = cf.getName();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   176
                    index = cf.attributes.getIndex(cf.constant_pool, annName);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   177
                    if(index!= -1) attr = cf.attributes.get(index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   178
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   179
        } catch(ConstantPoolException cpe) { cpe.printStackTrace(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   180
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   181
        if (index != -1) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   182
            if(isTAattr) { //count RuntimeTypeAnnotations
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   183
                RuntimeTypeAnnotations_attribute tAttr =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   184
                        (RuntimeTypeAnnotations_attribute)attr;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   185
                println(testtype + ": " + name + ", " + annName + ": " +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   186
                        tAttr.annotations.length );
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   187
                if (tAttr.annotations.length > 0) {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   188
                    for (int i = 0; i < tAttr.annotations.length; i++) {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   189
                        println("  types:" + tAttr.annotations[i].position.type);
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   190
                    }
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   191
                } else {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   192
                    println("");
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 17578
diff changeset
   193
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   194
                allt += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   195
                if (visible)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   196
                    tvisibles += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   197
                else
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   198
                    tinvisibles += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   199
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   200
                RuntimeAnnotations_attribute tAttr =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   201
                        (RuntimeAnnotations_attribute)attr;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   202
                println(testtype + ": " + name + ", " + annName + ": " +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   203
                        tAttr.annotations.length );
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   204
                all += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   205
                if (visible)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   206
                    visibles += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   207
                else
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   208
                    invisibles += tAttr.annotations.length;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   209
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   210
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   211
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   212
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   213
    void countAnnotations() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   214
        errors=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   215
        int expected_allt = expected_tvisibles + expected_tinvisibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   216
        int expected_all = expected_visibles + expected_invisibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   217
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   218
        if (expected_allt != allt) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   219
            errors++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   220
            System.err.println("Failure: expected " + expected_allt +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   221
                    " type annotations but found " + allt);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   222
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   223
        if (expected_all != all) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   224
            errors++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   225
            System.err.println("Failure: expected " + expected_all +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   226
                    " annotations but found " + all);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   227
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   228
        if (expected_tvisibles != tvisibles) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   229
            errors++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   230
            System.err.println("Failure: expected " + expected_tvisibles +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   231
                    " typevisible annotations but found " + tvisibles);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   232
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   233
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   234
        if (expected_tinvisibles != tinvisibles) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   235
            errors++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   236
            System.err.println("Failure: expected " + expected_tinvisibles +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   237
                    " typeinvisible annotations but found " + tinvisibles);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   238
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   239
        allt=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   240
        tvisibles=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   241
        tinvisibles=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   242
        all=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   243
        visibles=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   244
        invisibles=0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   245
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   246
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   247
    int errors;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   248
    int allt;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   249
    int tvisibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   250
    int tinvisibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   251
    int all;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   252
    int visibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   253
    int invisibles;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   254
}