src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42822 langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java@a84956e7ee4d
child 55242 77b54b2822cc
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:
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
     1
/*
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
     2
 * Copyright (c) 2007, 2016, 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: 5216
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: 5216
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: 5216
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5216
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5216
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
1039
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    28
import java.net.URI;
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents: 1039
diff changeset
    29
import java.text.DateFormat;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    30
import java.util.Collection;
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents: 1039
diff changeset
    31
import java.util.Date;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    32
import java.util.List;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    33
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    34
import com.sun.tools.classfile.AccessFlags;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    35
import com.sun.tools.classfile.Attribute;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    36
import com.sun.tools.classfile.Attributes;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    37
import com.sun.tools.classfile.ClassFile;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    38
import com.sun.tools.classfile.Code_attribute;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    39
import com.sun.tools.classfile.ConstantPool;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    40
import com.sun.tools.classfile.ConstantPoolException;
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
    41
import com.sun.tools.classfile.ConstantValue_attribute;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    42
import com.sun.tools.classfile.Descriptor;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
    43
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    44
import com.sun.tools.classfile.Exceptions_attribute;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    45
import com.sun.tools.classfile.Field;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    46
import com.sun.tools.classfile.Method;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    47
import com.sun.tools.classfile.Module_attribute;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    48
import com.sun.tools.classfile.Signature;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    49
import com.sun.tools.classfile.Signature_attribute;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    50
import com.sun.tools.classfile.SourceFile_attribute;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    51
import com.sun.tools.classfile.Type;
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    52
import com.sun.tools.classfile.Type.ArrayType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    53
import com.sun.tools.classfile.Type.ClassSigType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    54
import com.sun.tools.classfile.Type.ClassType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    55
import com.sun.tools.classfile.Type.MethodType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    56
import com.sun.tools.classfile.Type.SimpleType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    57
import com.sun.tools.classfile.Type.TypeParamType;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
    58
import com.sun.tools.classfile.Type.WildcardType;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    59
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    60
import static com.sun.tools.classfile.AccessFlags.*;
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    61
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Module;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    62
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Package;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    63
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    64
/*
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    65
 *  The main javap class to write the contents of a class file as text.
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    66
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    67
 *  <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
    68
 *  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
    69
 *  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
    70
 *  deletion without notice.</b>
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    71
 */
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    72
public class ClassWriter extends BasicWriter {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    73
    static ClassWriter instance(Context context) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    74
        ClassWriter instance = context.get(ClassWriter.class);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    75
        if (instance == null)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    76
            instance = new ClassWriter(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    77
        return instance;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    78
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    79
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    80
    protected ClassWriter(Context context) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    81
        super(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    82
        context.put(ClassWriter.class, this);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    83
        options = Options.instance(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    84
        attrWriter = AttributeWriter.instance(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    85
        codeWriter = CodeWriter.instance(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    86
        constantWriter = ConstantWriter.instance(context);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    87
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
    88
1039
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    89
    void setDigest(String name, byte[] digest) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    90
        this.digestName = name;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    91
        this.digest = digest;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    92
    }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    93
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    94
    void setFile(URI uri) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    95
        this.uri = uri;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    96
    }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    97
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    98
    void setFileSize(int size) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
    99
        this.size = size;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   100
    }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   101
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   102
    void setLastModified(long lastModified) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   103
        this.lastModified = lastModified;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   104
    }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   105
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   106
    protected ClassFile getClassFile() {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   107
        return classFile;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   108
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   109
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   110
    protected void setClassFile(ClassFile cf) {
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   111
        classFile = cf;
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   112
        constant_pool = classFile.constant_pool;
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   113
    }
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   114
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   115
    protected Method getMethod() {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   116
        return method;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   117
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   118
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   119
    protected void setMethod(Method m) {
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   120
        method = m;
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   121
    }
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   122
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   123
    public void write(ClassFile cf) {
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   124
        setClassFile(cf);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   125
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   126
        if (options.sysInfo || options.verbose) {
1039
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   127
            if (uri != null) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   128
                if (uri.getScheme().equals("file"))
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   129
                    println("Classfile " + uri.getPath());
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   130
                else
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   131
                    println("Classfile " + uri);
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   132
            }
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   133
            indent(+1);
1039
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   134
            if (lastModified != -1) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   135
                Date lm = new Date(lastModified);
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   136
                DateFormat df = DateFormat.getDateInstance();
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   137
                if (size > 0) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   138
                    println("Last modified " + df.format(lm) + "; size " + size + " bytes");
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   139
                } else {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   140
                    println("Last modified " + df.format(lm));
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   141
                }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   142
            } else if (size > 0) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   143
                println("Size " + size + " bytes");
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   144
            }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   145
            if (digestName != null && digest != null) {
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   146
                StringBuilder sb = new StringBuilder();
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   147
                for (byte b: digest)
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   148
                    sb.append(String.format("%02x", b));
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   149
                println(digestName + " checksum " + sb);
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   150
            }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   151
        }
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   152
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   153
        Attribute sfa = cf.getAttribute(Attribute.SourceFile);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   154
        if (sfa instanceof SourceFile_attribute) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   155
            println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\"");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   156
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   157
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   158
        if (options.sysInfo || options.verbose) {
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   159
            indent(-1);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   160
        }
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   161
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   162
        AccessFlags flags = cf.access_flags;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   163
        writeModifiers(flags.getClassModifiers());
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   164
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   165
        if (classFile.access_flags.is(AccessFlags.ACC_MODULE)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   166
            Attribute attr = classFile.attributes.get(Attribute.Module);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   167
            if (attr instanceof Module_attribute) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   168
                Module_attribute modAttr = (Module_attribute) attr;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   169
                String name;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   170
                try {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   171
                    // FIXME: compatibility code
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   172
                    if (constant_pool.get(modAttr.module_name).getTag() == CONSTANT_Module) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   173
                        name = getJavaName(constant_pool.getModuleInfo(modAttr.module_name).getName());
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   174
                    } else {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   175
                        name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   176
                    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   177
                } catch (ConstantPoolException e) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   178
                    name = report(e);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   179
                }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   180
                if ((modAttr.module_flags & Module_attribute.ACC_OPEN) != 0) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   181
                    print("open ");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   182
                }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   183
                print("module ");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   184
                print(name);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   185
                if (modAttr.module_version_index != 0) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   186
                    print("@");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   187
                    print(getUTF8Value(modAttr.module_version_index));
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   188
                }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   189
            } else {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   190
                // fallback for malformed class files
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   191
                print("class ");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   192
                print(getJavaName(classFile));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   193
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   194
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   195
            if (classFile.isClass())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   196
                print("class ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   197
            else if (classFile.isInterface())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   198
                print("interface ");
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   199
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   200
            print(getJavaName(classFile));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   201
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   202
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   203
        Signature_attribute sigAttr = getSignature(cf.attributes);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   204
        if (sigAttr == null) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   205
            // use info from class file header
859
16b1ea00598f 6715757: javap does not print "extends java.lang.Object"
jjg
parents: 735
diff changeset
   206
            if (classFile.isClass() && classFile.super_class != 0 ) {
16b1ea00598f 6715757: javap does not print "extends java.lang.Object"
jjg
parents: 735
diff changeset
   207
                String sn = getJavaSuperclassName(cf);
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   208
                if (!sn.equals("java.lang.Object")) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   209
                    print(" extends ");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   210
                    print(sn);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   211
                }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   212
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   213
            for (int i = 0; i < classFile.interfaces.length; i++) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   214
                print(i == 0 ? (classFile.isClass() ? " implements " : " extends ") : ",");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   215
                print(getJavaInterfaceName(classFile, i));
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   216
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   217
        } else {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   218
            try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   219
                Type t = sigAttr.getParsedSignature().getType(constant_pool);
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   220
                JavaTypePrinter p = new JavaTypePrinter(classFile.isInterface());
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   221
                // The signature parser cannot disambiguate between a
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   222
                // FieldType and a ClassSignatureType that only contains a superclass type.
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   223
                if (t instanceof Type.ClassSigType) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   224
                    print(p.print(t));
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   225
                } else if (options.verbose || !t.isObject()) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   226
                    print(" extends ");
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   227
                    print(p.print(t));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   228
                }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   229
            } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   230
                print(report(e));
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   231
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   232
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   233
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   234
        if (options.verbose) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   235
            println();
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   236
            indent(+1);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   237
            println("minor version: " + cf.minor_version);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   238
            println("major version: " + cf.major_version);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   239
            writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getClassFlags(), "\n");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   240
            print("this_class: #" + cf.this_class);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   241
            if (cf.this_class != 0) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   242
                tab();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   243
                print("// " + constantWriter.stringValue(cf.this_class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   244
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   245
            println();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   246
            print("super_class: #" + cf.super_class);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   247
            if (cf.super_class != 0) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   248
                tab();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   249
                print("// " + constantWriter.stringValue(cf.super_class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   250
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   251
            println();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   252
            print("interfaces: " + cf.interfaces.length);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   253
            print(", fields: " + cf.fields.length);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   254
            print(", methods: " + cf.methods.length);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   255
            println(", attributes: " + cf.attributes.attrs.length);
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   256
            indent(-1);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   257
            constantWriter.writeConstantPool();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   258
        } else {
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   259
            print(" ");
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   260
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   261
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   262
        println("{");
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   263
        indent(+1);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   264
        if (flags.is(AccessFlags.ACC_MODULE) && !options.verbose) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   265
            writeDirectives();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   266
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   267
        writeFields();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   268
        writeMethods();
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   269
        indent(-1);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   270
        println("}");
23797
756821688d0a 8035104: reorder class file attributes in javap listing
jjg
parents: 22698
diff changeset
   271
756821688d0a 8035104: reorder class file attributes in javap listing
jjg
parents: 22698
diff changeset
   272
        if (options.verbose) {
756821688d0a 8035104: reorder class file attributes in javap listing
jjg
parents: 22698
diff changeset
   273
            attrWriter.write(cf, cf.attributes, constant_pool);
756821688d0a 8035104: reorder class file attributes in javap listing
jjg
parents: 22698
diff changeset
   274
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   275
    }
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   276
    // where
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   277
        class JavaTypePrinter implements Type.Visitor<StringBuilder,StringBuilder> {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   278
            boolean isInterface;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   279
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   280
            JavaTypePrinter(boolean isInterface) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   281
                this.isInterface = isInterface;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   282
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   283
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   284
            String print(Type t) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   285
                return t.accept(this, new StringBuilder()).toString();
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   286
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   287
20618
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   288
            String printTypeArgs(List<? extends TypeParamType> typeParamTypes) {
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   289
                StringBuilder builder = new StringBuilder();
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   290
                appendIfNotEmpty(builder, "<", typeParamTypes, "> ");
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   291
                return builder.toString();
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   292
            }
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   293
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   294
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   295
            public StringBuilder visitSimpleType(SimpleType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   296
                sb.append(getJavaName(type.name));
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   297
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   298
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   299
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   300
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   301
            public StringBuilder visitArrayType(ArrayType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   302
                append(sb, type.elemType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   303
                sb.append("[]");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   304
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   305
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   306
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   307
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   308
            public StringBuilder visitMethodType(MethodType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   309
                appendIfNotEmpty(sb, "<", type.typeParamTypes, "> ");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   310
                append(sb, type.returnType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   311
                append(sb, " (", type.paramTypes, ")");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   312
                appendIfNotEmpty(sb, " throws ", type.throwsTypes, "");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   313
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   314
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   315
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   316
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   317
            public StringBuilder visitClassSigType(ClassSigType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   318
                appendIfNotEmpty(sb, "<", type.typeParamTypes, ">");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   319
                if (isInterface) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   320
                    appendIfNotEmpty(sb, " extends ", type.superinterfaceTypes, "");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   321
                } else {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   322
                    if (type.superclassType != null
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   323
                            && (options.verbose || !type.superclassType.isObject())) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   324
                        sb.append(" extends ");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   325
                        append(sb, type.superclassType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   326
                    }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   327
                    appendIfNotEmpty(sb, " implements ", type.superinterfaceTypes, "");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   328
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   329
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   330
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   331
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   332
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   333
            public StringBuilder visitClassType(ClassType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   334
                if (type.outerType != null) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   335
                    append(sb, type.outerType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   336
                    sb.append(".");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   337
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   338
                sb.append(getJavaName(type.name));
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   339
                appendIfNotEmpty(sb, "<", type.typeArgs, ">");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   340
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   341
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   342
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   343
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   344
            public StringBuilder visitTypeParamType(TypeParamType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   345
                sb.append(type.name);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   346
                String sep = " extends ";
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   347
                if (type.classBound != null
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   348
                        && (options.verbose || !type.classBound.isObject())) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   349
                    sb.append(sep);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   350
                    append(sb, type.classBound);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   351
                    sep = " & ";
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   352
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   353
                if (type.interfaceBounds != null) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   354
                    for (Type bound: type.interfaceBounds) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   355
                        sb.append(sep);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   356
                        append(sb, bound);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   357
                        sep = " & ";
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   358
                    }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   359
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   360
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   361
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   362
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   363
            @Override
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   364
            public StringBuilder visitWildcardType(WildcardType type, StringBuilder sb) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   365
                switch (type.kind) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   366
                    case UNBOUNDED:
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   367
                        sb.append("?");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   368
                        break;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   369
                    case EXTENDS:
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   370
                        sb.append("? extends ");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   371
                        append(sb, type.boundType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   372
                        break;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   373
                    case SUPER:
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   374
                        sb.append("? super ");
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   375
                        append(sb, type.boundType);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   376
                        break;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   377
                    default:
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   378
                        throw new AssertionError();
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   379
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   380
                return sb;
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   381
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   382
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   383
            private void append(StringBuilder sb, Type t) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   384
                t.accept(this, sb);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   385
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   386
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   387
            private void append(StringBuilder sb, String prefix, List<? extends Type> list, String suffix) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   388
                sb.append(prefix);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   389
                String sep = "";
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   390
                for (Type t: list) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   391
                    sb.append(sep);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   392
                    append(sb, t);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   393
                    sep = ", ";
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   394
                }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   395
                sb.append(suffix);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   396
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   397
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   398
            private void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> list, String suffix) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   399
                if (!isEmpty(list))
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   400
                    append(sb, prefix, list, suffix);
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   401
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   402
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   403
            private boolean isEmpty(List<? extends Type> list) {
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   404
                return (list == null || list.isEmpty());
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   405
            }
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   406
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   407
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   408
    protected void writeFields() {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   409
        for (Field f: classFile.fields) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   410
            writeField(f);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   411
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   412
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   413
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   414
    protected void writeField(Field f) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   415
        if (!options.checkAccess(f.access_flags))
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   416
            return;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   417
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   418
        AccessFlags flags = f.access_flags;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   419
        writeModifiers(flags.getFieldModifiers());
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   420
        Signature_attribute sigAttr = getSignature(f.attributes);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   421
        if (sigAttr == null)
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   422
            print(getJavaFieldType(f.descriptor));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   423
        else {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   424
            try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   425
                Type t = sigAttr.getParsedSignature().getType(constant_pool);
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   426
                print(getJavaName(t.toString()));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   427
            } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   428
                // report error?
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   429
                // fall back on non-generic descriptor
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   430
                print(getJavaFieldType(f.descriptor));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   431
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   432
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   433
        print(" ");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   434
        print(getFieldName(f));
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   435
        if (options.showConstants) {
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   436
            Attribute a = f.attributes.get(Attribute.ConstantValue);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   437
            if (a instanceof ConstantValue_attribute) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   438
                print(" = ");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   439
                ConstantValue_attribute cv = (ConstantValue_attribute) a;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   440
                print(getConstantValue(f.descriptor, cv.constantvalue_index));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   441
            }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   442
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   443
        print(";");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   444
        println();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   445
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   446
        indent(+1);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   447
22695
a290c74925d7 8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents: 22693
diff changeset
   448
        boolean showBlank = false;
a290c74925d7 8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents: 22693
diff changeset
   449
16291
d4249734ecd8 8007052: javap should include the descriptor for a method in verbose mode
jjg
parents: 15036
diff changeset
   450
        if (options.showDescriptors)
d4249734ecd8 8007052: javap should include the descriptor for a method in verbose mode
jjg
parents: 15036
diff changeset
   451
            println("descriptor: " + getValue(f.descriptor));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   452
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   453
        if (options.verbose)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   454
            writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getFieldFlags(), "\n");
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   455
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   456
        if (options.showAllAttrs) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   457
            for (Attribute attr: f.attributes)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   458
                attrWriter.write(f, attr, constant_pool);
22695
a290c74925d7 8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents: 22693
diff changeset
   459
            showBlank = true;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   460
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   461
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   462
        indent(-1);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   463
22695
a290c74925d7 8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents: 22693
diff changeset
   464
        if (showBlank || options.showDisassembled || options.showLineAndLocalVariableTables)
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   465
            println();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   466
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   467
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   468
    protected void writeMethods() {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   469
        for (Method m: classFile.methods)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   470
            writeMethod(m);
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   471
        setPendingNewline(false);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   472
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   473
3141
79c119fae7fb 6852856: javap changes to facilitate subclassing javap for variants
jjg
parents: 2979
diff changeset
   474
    protected void writeMethod(Method m) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   475
        if (!options.checkAccess(m.access_flags))
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   476
            return;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   477
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   478
        method = m;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   479
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   480
        AccessFlags flags = m.access_flags;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   481
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   482
        Descriptor d;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   483
        Type.MethodType methodType;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   484
        List<? extends Type> methodExceptions;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   485
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   486
        Signature_attribute sigAttr = getSignature(m.attributes);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   487
        if (sigAttr == null) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   488
            d = m.descriptor;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   489
            methodType = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   490
            methodExceptions = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   491
        } else {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   492
            Signature methodSig = sigAttr.getParsedSignature();
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   493
            d = methodSig;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   494
            try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   495
                methodType = (Type.MethodType) methodSig.getType(constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   496
                methodExceptions = methodType.throwsTypes;
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 7681
diff changeset
   497
                if (methodExceptions != null && methodExceptions.isEmpty())
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   498
                    methodExceptions = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   499
            } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   500
                // report error?
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   501
                // fall back on standard descriptor
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   502
                methodType = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   503
                methodExceptions = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   504
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   505
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   506
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   507
        writeModifiers(flags.getMethodModifiers());
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   508
        if (methodType != null) {
20618
313dc106ebca 8003537: javap use internal class name when printing bound of type variable
ksrini
parents: 16291
diff changeset
   509
            print(new JavaTypePrinter(false).printTypeArgs(methodType.typeParamTypes));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   510
        }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   511
        switch (getName(m)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   512
            case "<init>":
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   513
                print(getJavaName(classFile));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   514
                print(getJavaParameterTypes(d, flags));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   515
                break;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   516
            case "<clinit>":
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   517
                print("{}");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   518
                break;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   519
            default:
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   520
                print(getJavaReturnType(d));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   521
                print(" ");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   522
                print(getName(m));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   523
                print(getJavaParameterTypes(d, flags));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   524
                break;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   525
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   526
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   527
        Attribute e_attr = m.attributes.get(Attribute.Exceptions);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   528
        if (e_attr != null) { // if there are generic exceptions, there must be erased exceptions
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   529
            if (e_attr instanceof Exceptions_attribute) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   530
                Exceptions_attribute exceptions = (Exceptions_attribute) e_attr;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   531
                print(" throws ");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   532
                if (methodExceptions != null) { // use generic list if available
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   533
                    writeList("", methodExceptions, "");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   534
                } else {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   535
                    for (int i = 0; i < exceptions.number_of_exceptions; i++) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   536
                        if (i > 0)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   537
                            print(", ");
733
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   538
                        print(getJavaException(exceptions, i));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   539
                    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   540
                }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   541
            } else {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   542
                report("Unexpected or invalid value for Exceptions attribute");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   543
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   544
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   545
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   546
        println(";");
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   547
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   548
        indent(+1);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   549
16291
d4249734ecd8 8007052: javap should include the descriptor for a method in verbose mode
jjg
parents: 15036
diff changeset
   550
        if (options.showDescriptors) {
d4249734ecd8 8007052: javap should include the descriptor for a method in verbose mode
jjg
parents: 15036
diff changeset
   551
            println("descriptor: " + getValue(m.descriptor));
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   552
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   553
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   554
        if (options.verbose) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   555
            writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getMethodFlags(), "\n");
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   556
        }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   557
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   558
        Code_attribute code = null;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   559
        Attribute c_attr = m.attributes.get(Attribute.Code);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   560
        if (c_attr != null) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   561
            if (c_attr instanceof Code_attribute)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   562
                code = (Code_attribute) c_attr;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   563
            else
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   564
                report("Unexpected or invalid value for Code attribute");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   565
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   566
22693
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   567
        if (options.showAllAttrs) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   568
            Attribute[] attrs = m.attributes.attrs;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   569
            for (Attribute attr: attrs)
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   570
                attrWriter.write(m, attr, constant_pool);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   571
        } else if (code != null) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   572
            if (options.showDisassembled) {
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   573
                println("Code:");
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   574
                codeWriter.writeInstrs(code);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   575
                codeWriter.writeExceptionTable(code);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   576
            }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   577
22693
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents: 20618
diff changeset
   578
            if (options.showLineAndLocalVariableTables) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   579
                attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   580
                attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool);
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   581
            }
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   582
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   583
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   584
        indent(-1);
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   585
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   586
        // set pendingNewline to write a newline before the next method (if any)
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   587
        // if a separator is desired
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   588
        setPendingNewline(
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   589
                options.showDisassembled ||
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   590
                options.showAllAttrs ||
16291
d4249734ecd8 8007052: javap should include the descriptor for a method in verbose mode
jjg
parents: 15036
diff changeset
   591
                options.showDescriptors ||
3546
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   592
                options.showLineAndLocalVariableTables ||
00b2974fdf04 6867671: javap whitespace formatting issues
jjg
parents: 3141
diff changeset
   593
                options.verbose);
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   594
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   595
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   596
    void writeModifiers(Collection<String> items) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   597
        for (Object item: items) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   598
            print(item);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   599
            print(" ");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   600
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   601
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   602
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   603
    void writeDirectives() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   604
        Attribute attr = classFile.attributes.get(Attribute.Module);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   605
        if (!(attr instanceof Module_attribute))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   606
            return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   607
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   608
        Module_attribute m = (Module_attribute) attr;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   609
        for (Module_attribute.RequiresEntry entry: m.requires) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   610
            print("requires");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   611
            if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   612
                print(" static");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   613
            if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   614
                print(" transitive");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   615
            print(" ");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   616
            String mname;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   617
            try {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   618
                mname = getModuleName(entry.requires_index);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   619
            } catch (ConstantPoolException e) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   620
                mname = report(e);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   621
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   622
            print(mname);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   623
            println(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   624
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   625
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   626
        for (Module_attribute.ExportsEntry entry: m.exports) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   627
            print("exports");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   628
            print(" ");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   629
            String pname;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   630
            try {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   631
                pname = getPackageName(entry.exports_index).replace('/', '.');
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   632
            } catch (ConstantPoolException e) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   633
                pname = report(e);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   634
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   635
            print(pname);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   636
            boolean first = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   637
            for (int i: entry.exports_to_index) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   638
                String mname;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   639
                try {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   640
                    mname = getModuleName(i);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   641
                } catch (ConstantPoolException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   642
                    mname = report(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   643
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   644
                if (first) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   645
                    println(" to");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   646
                    indent(+1);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   647
                    first = false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   648
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   649
                    println(",");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   650
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   651
                print(mname);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   652
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   653
            println(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   654
            if (!first)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   655
                indent(-1);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   656
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   657
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   658
        for (Module_attribute.OpensEntry entry: m.opens) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   659
            print("opens");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   660
            print(" ");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   661
            String pname;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   662
            try {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   663
                pname = getPackageName(entry.opens_index).replace('/', '.');
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   664
            } catch (ConstantPoolException e) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   665
                pname = report(e);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   666
            }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   667
            print(pname);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   668
            boolean first = true;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   669
            for (int i: entry.opens_to_index) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   670
                String mname;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   671
                try {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   672
                    mname = getModuleName(i);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   673
                } catch (ConstantPoolException e) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   674
                    mname = report(e);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   675
                }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   676
                if (first) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   677
                    println(" to");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   678
                    indent(+1);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   679
                    first = false;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   680
                } else {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   681
                    println(",");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   682
                }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   683
                print(mname);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   684
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   685
            println(";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   686
            if (!first)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   687
                indent(-1);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   688
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   689
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   690
        for (int entry: m.uses_index) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   691
            print("uses ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   692
            print(getClassName(entry).replace('/', '.'));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   693
            println(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   694
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   695
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   696
        for (Module_attribute.ProvidesEntry entry: m.provides) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   697
            print("provides  ");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   698
            print(getClassName(entry.provides_index).replace('/', '.'));
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   699
            boolean first = true;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   700
            for (int i: entry.with_index) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   701
                if (first) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   702
                    println(" with");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   703
                    indent(+1);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   704
                    first = false;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   705
                } else {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   706
                    println(",");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   707
                }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   708
                print(getClassName(i).replace('/', '.'));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   709
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   710
            println(";");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   711
            if (!first)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   712
                indent(-1);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   713
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   714
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   715
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   716
    String getModuleName(int index) throws ConstantPoolException {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   717
        if (constant_pool.get(index).getTag() == CONSTANT_Module) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   718
            return constant_pool.getModuleInfo(index).getName();
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   719
        } else {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   720
            return constant_pool.getUTF8Value(index);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   721
        }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   722
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   723
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   724
    String getPackageName(int index) throws ConstantPoolException {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   725
        if (constant_pool.get(index).getTag() == CONSTANT_Package) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   726
            return constant_pool.getPackageInfo(index).getName();
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   727
        } else {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   728
            return constant_pool.getUTF8Value(index);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   729
        }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   730
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   731
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   732
    String getUTF8Value(int index) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   733
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   734
            return classFile.constant_pool.getUTF8Value(index);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   735
        } catch (ConstantPoolException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   736
            return report(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   737
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   738
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   739
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   740
    String getClassName(int index) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   741
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   742
            return classFile.constant_pool.getClassInfo(index).getName();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   743
        } catch (ConstantPoolException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   744
            return report(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   745
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   746
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
   747
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   748
    void writeList(String prefix, Collection<?> items, String suffix) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   749
        print(prefix);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   750
        String sep = "";
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   751
        for (Object item: items) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   752
            print(sep);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   753
            print(item);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   754
            sep = ", ";
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   755
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   756
        print(suffix);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   757
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   758
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   759
    void writeListIfNotEmpty(String prefix, List<?> items, String suffix) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   760
        if (items != null && items.size() > 0)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   761
            writeList(prefix, items, suffix);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   762
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   763
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   764
    Signature_attribute getSignature(Attributes attributes) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   765
        return (Signature_attribute) attributes.get(Attribute.Signature);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   766
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   767
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   768
    String adjustVarargs(AccessFlags flags, String params) {
22698
818555741cd5 8032869: remove support for legacy options in javap
jjg
parents: 22695
diff changeset
   769
        if (flags.is(ACC_VARARGS)) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   770
            int i = params.lastIndexOf("[]");
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   771
            if (i > 0)
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   772
                return params.substring(0, i) + "..." + params.substring(i+2);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   773
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   774
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   775
        return params;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   776
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   777
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   778
    String getJavaName(ClassFile cf) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   779
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   780
            return getJavaName(cf.getName());
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   781
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   782
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   783
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   784
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   785
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   786
    String getJavaSuperclassName(ClassFile cf) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   787
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   788
            return getJavaName(cf.getSuperclassName());
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   789
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   790
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   791
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   792
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   793
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   794
    String getJavaInterfaceName(ClassFile cf, int index) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   795
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   796
            return getJavaName(cf.getInterfaceName(index));
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   797
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   798
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   799
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   800
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   801
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   802
    String getJavaFieldType(Descriptor d) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   803
        try {
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   804
            return getJavaName(d.getFieldType(constant_pool));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   805
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   806
            return report(e);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   807
        } catch (InvalidDescriptor e) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   808
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   809
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   810
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   811
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   812
    String getJavaReturnType(Descriptor d) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   813
        try {
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   814
            return getJavaName(d.getReturnType(constant_pool));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   815
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   816
            return report(e);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   817
        } catch (InvalidDescriptor e) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   818
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   819
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   820
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   821
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   822
    String getJavaParameterTypes(Descriptor d, AccessFlags flags) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   823
        try {
5216
b7f7018fa96a 6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents: 4076
diff changeset
   824
            return getJavaName(adjustVarargs(flags, d.getParameterTypes(constant_pool)));
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   825
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   826
            return report(e);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   827
        } catch (InvalidDescriptor e) {
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   828
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   829
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   830
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   831
733
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   832
    String getJavaException(Exceptions_attribute attr, int index) {
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   833
        try {
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   834
            return getJavaName(attr.getException(index, constant_pool));
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   835
        } catch (ConstantPoolException e) {
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   836
            return report(e);
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   837
        }
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   838
    }
b76c4357c649 6715767: javap on java.lang.ClassLoader crashes
jjg
parents: 727
diff changeset
   839
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   840
    String getValue(Descriptor d) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   841
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   842
            return d.getValue(constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   843
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   844
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   845
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   846
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   847
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   848
    String getFieldName(Field f) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   849
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   850
            return f.getName(constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   851
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   852
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   853
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   854
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   855
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   856
    String getName(Method m) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   857
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   858
            return m.getName(constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   859
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   860
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   861
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   862
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   863
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   864
    static String getJavaName(String name) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   865
        return name.replace('/', '.');
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   866
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   867
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   868
    String getSourceFile(SourceFile_attribute attr) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   869
        try {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   870
            return attr.getSourceFile(constant_pool);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   871
        } catch (ConstantPoolException e) {
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   872
            return report(e);
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   873
        }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   874
    }
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   875
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   876
    /**
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   877
     * Get the value of an entry in the constant pool as a Java constant.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   878
     * Characters and booleans are represented by CONSTANT_Intgere entries.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   879
     * Character and string values are processed to escape characters outside
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   880
     * the basic printable ASCII set.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   881
     * @param d the descriptor, giving the expected type of the constant
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   882
     * @param index the index of the value in the constant pool
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   883
     * @return a printable string containing the value of the constant.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   884
     */
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   885
    String getConstantValue(Descriptor d, int index) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   886
        try {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   887
            ConstantPool.CPInfo cpInfo = constant_pool.get(index);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   888
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   889
            switch (cpInfo.getTag()) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   890
                case ConstantPool.CONSTANT_Integer: {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   891
                    ConstantPool.CONSTANT_Integer_info info =
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   892
                            (ConstantPool.CONSTANT_Integer_info) cpInfo;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   893
                    String t = d.getValue(constant_pool);
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   894
                    switch (t) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   895
                        case "C":
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   896
                            // character
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   897
                            return getConstantCharValue((char) info.value);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   898
                        case "Z":
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   899
                            // boolean
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   900
                            return String.valueOf(info.value == 1);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   901
                        default:
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   902
                            // other: assume integer
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   903
                            return String.valueOf(info.value);
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   904
                    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   905
                }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   906
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   907
                case ConstantPool.CONSTANT_String: {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   908
                    ConstantPool.CONSTANT_String_info info =
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   909
                            (ConstantPool.CONSTANT_String_info) cpInfo;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   910
                    return getConstantStringValue(info.getString());
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   911
                }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   912
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   913
                default:
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   914
                    return constantWriter.stringValue(cpInfo);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   915
            }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   916
        } catch (ConstantPoolException e) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   917
            return "#" + index;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   918
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   919
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   920
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   921
    private String getConstantCharValue(char c) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   922
        StringBuilder sb = new StringBuilder();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   923
        sb.append('\'');
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   924
        sb.append(esc(c, '\''));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   925
        sb.append('\'');
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   926
        return sb.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   927
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   928
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   929
    private String getConstantStringValue(String s) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   930
        StringBuilder sb = new StringBuilder();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   931
        sb.append("\"");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   932
        for (int i = 0; i < s.length(); i++) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   933
            sb.append(esc(s.charAt(i), '"'));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   934
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   935
        sb.append("\"");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   936
        return sb.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   937
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   938
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   939
    private String esc(char c, char quote) {
39919
3d3573afc062 8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents: 36526
diff changeset
   940
        if (32 <= c && c <= 126 && c != quote && c != '\\')
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   941
            return String.valueOf(c);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   942
        else switch (c) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   943
            case '\b': return "\\b";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   944
            case '\n': return "\\n";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   945
            case '\t': return "\\t";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   946
            case '\f': return "\\f";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   947
            case '\r': return "\\r";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   948
            case '\\': return "\\\\";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   949
            case '\'': return "\\'";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   950
            case '\"': return "\\\"";
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   951
            default:   return String.format("\\u%04x", (int) c);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   952
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   953
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents: 859
diff changeset
   954
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   955
    private final Options options;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   956
    private final AttributeWriter attrWriter;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   957
    private final CodeWriter codeWriter;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39919
diff changeset
   958
    private final ConstantWriter constantWriter;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   959
    private ClassFile classFile;
1039
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   960
    private URI uri;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   961
    private long lastModified;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   962
    private String digestName;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   963
    private byte[] digest;
ca7b8a8c9268 4884240: additional option required for javap
jjg
parents: 1038
diff changeset
   964
    private int size;
727
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   965
    private ConstantPool constant_pool;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   966
    private Method method;
cb50c1ae7bab 4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff changeset
   967
}