src/jdk.jdeps/share/classes/com/sun/tools/javap/AnnotationWriter.java
author jjg
Tue, 21 Nov 2017 13:06:43 -0800
changeset 47875 93bba74ed8a3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8156694: javap should render annotations in a friendly way Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     1
/*
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     4
 *
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4873
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4873
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    10
 *
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    15
 * accompanied this code).
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    16
 *
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4873
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4873
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4873
diff changeset
    23
 * questions.
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    24
 */
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    25
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    26
package com.sun.tools.javap;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    27
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    28
import com.sun.tools.classfile.Annotation;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
    29
import com.sun.tools.classfile.TypeAnnotation;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    30
import com.sun.tools.classfile.Annotation.Annotation_element_value;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    31
import com.sun.tools.classfile.Annotation.Array_element_value;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    32
import com.sun.tools.classfile.Annotation.Class_element_value;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    33
import com.sun.tools.classfile.Annotation.Enum_element_value;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    34
import com.sun.tools.classfile.Annotation.Primitive_element_value;
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    35
import com.sun.tools.classfile.ConstantPool;
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    36
import com.sun.tools.classfile.ConstantPoolException;
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    37
import com.sun.tools.classfile.Descriptor;
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    38
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    39
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    40
/**
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    41
 *  A writer for writing annotations as text.
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    42
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    43
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    44
 *  If you write code that depends on this, you do so at your own risk.
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    45
 *  This code and its internal interfaces are subject to change or
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    46
 *  deletion without notice.</b>
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    47
 */
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    48
public class AnnotationWriter extends BasicWriter {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    49
    static AnnotationWriter instance(Context context) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    50
        AnnotationWriter instance = context.get(AnnotationWriter.class);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    51
        if (instance == null)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    52
            instance = new AnnotationWriter(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    53
        return instance;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    54
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    55
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    56
    protected AnnotationWriter(Context context) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    57
        super(context);
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    58
        classWriter = ClassWriter.instance(context);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    59
        constantWriter = ConstantWriter.instance(context);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    60
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    61
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    62
    public void write(Annotation annot) {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    63
        write(annot, false);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    64
        println();
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    65
        indent(+1);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    66
        write(annot, true);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    67
        indent(-1);
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    68
    }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    69
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    70
    public void write(Annotation annot, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    71
        writeDescriptor(annot.type_index, resolveIndices);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    72
        if (resolveIndices) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    73
            boolean showParens = annot.num_element_value_pairs > 0;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    74
            if (showParens) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    75
                println("(");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    76
                indent(+1);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    77
            }
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    78
            for (int i = 0; i < annot.num_element_value_pairs; i++) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    79
                write(annot.element_value_pairs[i], true);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    80
                println();
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    81
            }
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    82
            if (showParens) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    83
                indent(-1);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    84
                print(")");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    85
            }
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    86
        } else {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
    87
            print("(");
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    88
            for (int i = 0; i < annot.num_element_value_pairs; i++) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    89
                if (i > 0)
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    90
                    print(",");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    91
                write(annot.element_value_pairs[i], false);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    92
            }
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    93
            print(")");
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    94
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    95
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    96
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
    97
    public void write(TypeAnnotation annot) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
    98
        write(annot, true, false);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
    99
        println();
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   100
        indent(+1);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   101
        write(annot.annotation, true);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   102
        indent(-1);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   103
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   104
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   105
    public void write(TypeAnnotation annot, boolean showOffsets, boolean resolveIndices) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   106
        write(annot.annotation, resolveIndices);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   107
        print(": ");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   108
        write(annot.position, showOffsets);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   109
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   110
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   111
    public void write(TypeAnnotation.Position pos, boolean showOffsets) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   112
        print(pos.type);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   113
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   114
        switch (pos.type) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   115
        // instanceof
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   116
        case INSTANCEOF:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   117
        // new expression
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   118
        case NEW:
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   119
        // constructor/method reference receiver
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   120
        case CONSTRUCTOR_REFERENCE:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   121
        case METHOD_REFERENCE:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   122
            if (showOffsets) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   123
                print(", offset=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   124
                print(pos.offset);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   125
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   126
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   127
        // local variable
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   128
        case LOCAL_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   129
        // resource variable
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   130
        case RESOURCE_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   131
            if (pos.lvarOffset == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   132
                print(", lvarOffset is Null!");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   133
                break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   134
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   135
            print(", {");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   136
            for (int i = 0; i < pos.lvarOffset.length; ++i) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   137
                if (i != 0) print("; ");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   138
                if (showOffsets) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   139
                    print("start_pc=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   140
                    print(pos.lvarOffset[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   141
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   142
                print(", length=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   143
                print(pos.lvarLength[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   144
                print(", index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   145
                print(pos.lvarIndex[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   146
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   147
            print("}");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   148
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   149
        // exception parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   150
        case EXCEPTION_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   151
            print(", exception_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   152
            print(pos.exception_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   153
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   154
        // method receiver
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   155
        case METHOD_RECEIVER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   156
            // Do nothing
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   157
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   158
        // type parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   159
        case CLASS_TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   160
        case METHOD_TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   161
            print(", param_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   162
            print(pos.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   163
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   164
        // type parameter bound
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   165
        case CLASS_TYPE_PARAMETER_BOUND:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   166
        case METHOD_TYPE_PARAMETER_BOUND:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   167
            print(", param_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   168
            print(pos.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   169
            print(", bound_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   170
            print(pos.bound_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   171
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   172
        // class extends or implements clause
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   173
        case CLASS_EXTENDS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   174
            print(", type_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   175
            print(pos.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   176
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   177
        // throws
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   178
        case THROWS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   179
            print(", type_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   180
            print(pos.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   181
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   182
        // method parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   183
        case METHOD_FORMAL_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   184
            print(", param_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   185
            print(pos.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   186
            break;
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   187
        // type cast
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   188
        case CAST:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   189
        // method/constructor/reference type argument
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   190
        case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   191
        case METHOD_INVOCATION_TYPE_ARGUMENT:
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   192
        case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   193
        case METHOD_REFERENCE_TYPE_ARGUMENT:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   194
            if (showOffsets) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   195
                print(", offset=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   196
                print(pos.offset);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   197
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   198
            print(", type_index=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   199
            print(pos.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   200
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   201
        // We don't need to worry about these
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   202
        case METHOD_RETURN:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   203
        case FIELD:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   204
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   205
        case UNKNOWN:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   206
            throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   207
        default:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   208
            throw new AssertionError("AnnotationWriter: Unknown target type for position: " + pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   209
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   210
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   211
        // Append location data for generics/arrays.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   212
        if (!pos.location.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   213
            print(", location=");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   214
            print(pos.location);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   215
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   216
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 8031
diff changeset
   217
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   218
    public void write(Annotation.element_value_pair pair, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   219
        writeIndex(pair.element_name_index, resolveIndices);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   220
        print("=");
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   221
        write(pair.value, resolveIndices);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   222
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   223
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   224
    public void write(Annotation.element_value value) {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   225
        write(value, false);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   226
        println();
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   227
        indent(+1);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   228
        write(value, true);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   229
        indent(-1);
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   230
    }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   231
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   232
    public void write(Annotation.element_value value, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   233
        ev_writer.write(value, resolveIndices);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   234
    }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   235
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   236
    private void writeDescriptor(int index, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   237
        if (resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   238
            try {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   239
                ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   240
                Descriptor d = new Descriptor(index);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   241
                print(d.getFieldType(constant_pool));
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   242
                return;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15718
diff changeset
   243
            } catch (ConstantPoolException | InvalidDescriptor ignore) {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   244
            }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   245
        }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   246
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   247
        print("#" + index);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   248
    }
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   249
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   250
    private void writeIndex(int index, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   251
        if (resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   252
            print(constantWriter.stringValue(index));
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   253
        } else
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   254
            print("#" + index);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   255
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   256
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   257
    element_value_Writer ev_writer = new element_value_Writer();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   258
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   259
    class element_value_Writer implements Annotation.element_value.Visitor<Void,Boolean> {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   260
        public void write(Annotation.element_value value, boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   261
            value.accept(this, resolveIndices);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   262
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   263
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   264
        @Override
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   265
        public Void visitPrimitive(Primitive_element_value ev, Boolean resolveIndices) {
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   266
            if (resolveIndices) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   267
                int index = ev.const_value_index;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   268
                switch (ev.tag) {
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   269
                    case 'B':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   270
                        print("(byte) ");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   271
                        print(constantWriter.stringValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   272
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   273
                    case 'C':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   274
                        print("'");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   275
                        print(constantWriter.charValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   276
                        print("'");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   277
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   278
                    case 'D':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   279
                    case 'F':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   280
                    case 'I':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   281
                    case 'J':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   282
                        print(constantWriter.stringValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   283
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   284
                    case 'S':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   285
                        print("(short) ");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   286
                        print(constantWriter.stringValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   287
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   288
                    case 'Z':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   289
                        print(constantWriter.booleanValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   290
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   291
                    case 's':
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   292
                        print("\"");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   293
                        print(constantWriter.stringValue(index));
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   294
                        print("\"");
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   295
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   296
                    default:
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   297
                        print(((char) ev.tag) + "#" + ev.const_value_index);
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   298
                        break;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   299
                }
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   300
            } else {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   301
                print(((char) ev.tag) + "#" + ev.const_value_index);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   302
            }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   303
            return null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   304
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   305
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   306
        @Override
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   307
        public Void visitEnum(Enum_element_value ev, Boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   308
            if (resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   309
                writeIndex(ev.type_name_index, resolveIndices);
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   310
                print(".");
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   311
                writeIndex(ev.const_name_index, resolveIndices);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   312
            } else {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   313
                print(((char) ev.tag) + "#" + ev.type_name_index + ".#" + ev.const_name_index);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   314
            }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   315
            return null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   316
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   317
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   318
        @Override
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   319
        public Void visitClass(Class_element_value ev, Boolean resolveIndices) {
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   320
            if (resolveIndices) {
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   321
                print("class ");
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   322
                writeIndex(ev.class_info_index, resolveIndices);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   323
            } else {
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   324
                print(((char) ev.tag) + "#" + ev.class_info_index);
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   325
            }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   326
            return null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   327
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   328
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   329
        @Override
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   330
        public Void visitAnnotation(Annotation_element_value ev, Boolean resolveIndices) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   331
            print((char) ev.tag);
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   332
            AnnotationWriter.this.write(ev.annotation_value, resolveIndices);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   333
            return null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   334
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   335
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   336
        @Override
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   337
        public Void visitArray(Array_element_value ev, Boolean resolveIndices) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   338
            print("[");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   339
            for (int i = 0; i < ev.num_values; i++) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   340
                if (i > 0)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   341
                    print(",");
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   342
                write(ev.values[i], resolveIndices);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   343
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   344
            print("]");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   345
            return null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   346
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   347
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   348
    }
3536
dee1b5833af7 6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents: 3149
diff changeset
   349
47875
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   350
    private final ClassWriter classWriter;
93bba74ed8a3 8156694: javap should render annotations in a friendly way
jjg
parents: 47216
diff changeset
   351
    private final ConstantWriter constantWriter;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   352
}