1 /* 2 * Copyright (c) 2018, 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 26 import org.openjdk.asmtools.jasm.JasmTokens; 27 28 import java.io.DataInputStream; 29 import java.io.IOException; 30 31 /** 32 * The NestHost attribute data 33 * <p> 34 * since class file 55.0 (JEP 181) 35 */ 36 public class NestHostData extends Indenter{ 37 ClassData cls; 38 int host_class_index; 39 private Options options = Options.OptionObject(); 40 41 public NestHostData(ClassData cls) { 42 this.cls = cls; 43 } 44 45 public NestHostData read(DataInputStream in, int attribute_length) throws IOException, ClassFormatError { 46 if (attribute_length != 2) { 47 throw new ClassFormatError("ATT_NestHost: Invalid attribute length"); 48 } 49 host_class_index = in.readUnsignedShort(); 50 return this; 51 } 52 53 public void print() { 54 boolean pr_cpx = options.contains(Options.PR.CPX); 55 cls.out.print(getIndentString() + JasmTokens.Token.NESTHOST.parseKey() + " "); 56 if (pr_cpx) { 57 cls.out.print("#" + host_class_index + "; //"); 58 } 59 if (pr_cpx) { 60 cls.pool.PrintConstant(cls.out, host_class_index); 61 cls.out.println(); 62 } else { 63 cls.out.println(cls.pool.StringValue(host_class_index) + ";"); 64 } 65 } 66 }