1 /*
 2  * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package org.openjdk.asmtools.jdis;
24 
25 import static org.openjdk.asmtools.jasm.Tables.*;
26 import org.openjdk.asmtools.jasm.Modifiers;
27 import java.io.DataInputStream;
28 import java.io.IOException;
29 
30 /**
31  *
32  */
33 class InnerClassData extends Indenter {
34 
35     ClassData cls;
36     int inner_class_info_index;
37     int outer_class_info_index;
38     int inner_name_index;
39     int access;
40     /*-------------------------------------------------------- */
41 
42     public InnerClassData(ClassData cls) {
43         this.cls = cls;
44     }
45 
46     public void read(DataInputStream in) throws IOException {
47         inner_class_info_index = in.readUnsignedShort();
48         outer_class_info_index = in.readUnsignedShort();
49         inner_name_index = in.readUnsignedShort();
50         access = in.readUnsignedShort();
51     }  // end read
52 
53     public void print() throws IOException {
54         boolean pr_cpx = Options.OptionObject().contains(Options.PR.CPX);
55         cls.out.print(getIndentString() + Modifiers.accessString(access, CF_Context.CTX_INNERCLASS));
56         cls.out.print("InnerClass ");
57         if (pr_cpx) {
58             if (inner_name_index != 0) {
59                 cls.out.print("#" + inner_name_index + "= ");
60             }
61             cls.out.print("#" + inner_class_info_index);
62             if (outer_class_info_index != 0) {
63                 cls.out.print(" of #" + outer_class_info_index);
64             }
65             cls.out.print("; // ");
66         }
67         if (inner_name_index != 0) {
68             cls.out.print(cls.pool.getName(inner_name_index) + "=");
69         }
70         if (inner_class_info_index != 0) {
71             cls.pool.PrintConstant(cls.out, inner_class_info_index);
72         }
73         if (outer_class_info_index != 0) {
74             cls.out.print(" of ");
75             cls.pool.PrintConstant(cls.out, outer_class_info_index);
76         }
77         if (pr_cpx) {
78             cls.out.println();
79         } else {
80             cls.out.println(";");
81         }
82     }
83 } // end InnerClassData
84