1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.classfile; 23 24 import java.io.DataInput; 25 import java.io.DataOutputStream; 26 import java.io.IOException; 27 28 import com.sun.org.apache.bcel.internal.Const; 29 30 /** 31 * This class is derived from <em>Attribute</em> and represents a reference 32 * to a PMG attribute. 33 * 34 * @see Attribute 35 */ 36 public final class PMGClass extends Attribute { 37 38 private int pmg_class_index; 39 private int pmg_index; 40 41 42 /** 43 * Initialize from another object. Note that both objects use the same 44 * references (shallow copy). Use copy() for a physical copy. 45 */ 46 public PMGClass(final PMGClass c) { 47 this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), c 48 .getConstantPool()); 49 } 50 51 52 /** 53 * Construct object from input stream. 54 * @param name_index Index in constant pool to CONSTANT_Utf8 55 * @param length Content length in bytes 56 * @param input Input stream 57 * @param constant_pool Array of constants 58 * @throws IOException 59 */ 60 PMGClass(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) 61 throws IOException { 62 this(name_index, length, input.readUnsignedShort(), input.readUnsignedShort(), constant_pool); 63 } 64 65 66 /** 67 * @param name_index Index in constant pool to CONSTANT_Utf8 68 * @param length Content length in bytes 69 * @param pmg_index index in constant pool for source file name 70 * @param pmg_class_index Index in constant pool to CONSTANT_Utf8 71 * @param constant_pool Array of constants 72 */ 73 public PMGClass(final int name_index, final int length, final int pmg_index, final int pmg_class_index, 74 final ConstantPool constant_pool) { 75 super(Const.ATTR_PMG, name_index, length, constant_pool); 76 this.pmg_index = pmg_index; 77 this.pmg_class_index = pmg_class_index; 78 } 79 80 81 /** 82 * Called by objects that are traversing the nodes of the tree implicitely 83 * defined by the contents of a Java class. I.e., the hierarchy of methods, 84 * fields, attributes, etc. spawns a tree of objects. 85 * 86 * @param v Visitor object 87 */ 88 @Override 89 public void accept( final Visitor v ) { 90 println("Visiting non-standard PMGClass object"); 91 } 92 93 94 /** 95 * Dump source file attribute to file stream in binary format. 96 * 97 * @param file Output file stream 98 * @throws IOException 99 */ 100 @Override 101 public void dump( final DataOutputStream file ) throws IOException { 102 super.dump(file); 103 file.writeShort(pmg_index); 104 file.writeShort(pmg_class_index); 105 } 106 107 108 /** 109 * @return Index in constant pool of source file name. 110 */ 111 public int getPMGClassIndex() { 112 return pmg_class_index; 113 } 114 115 116 /** 117 * @param pmg_class_index 118 */ 119 public void setPMGClassIndex( final int pmg_class_index ) { 120 this.pmg_class_index = pmg_class_index; 121 } 122 123 124 /** 125 * @return Index in constant pool of source file name. 126 */ 127 public int getPMGIndex() { 128 return pmg_index; 129 } 130 131 132 /** 133 * @param pmg_index 134 */ 135 public void setPMGIndex( final int pmg_index ) { 136 this.pmg_index = pmg_index; 137 } 138 139 140 /** 141 * @return PMG name. 142 */ 143 public String getPMGName() { 144 final ConstantUtf8 c = (ConstantUtf8) super.getConstantPool().getConstant(pmg_index, 145 Const.CONSTANT_Utf8); 146 return c.getBytes(); 147 } 148 149 150 /** 151 * @return PMG class name. 152 */ 153 public String getPMGClassName() { 154 final ConstantUtf8 c = (ConstantUtf8) super.getConstantPool().getConstant(pmg_class_index, 155 Const.CONSTANT_Utf8); 156 return c.getBytes(); 157 } 158 159 160 /** 161 * @return String representation 162 */ 163 @Override 164 public String toString() { 165 return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")"; 166 } 167 168 169 /** 170 * @return deep copy of this attribute 171 */ 172 @Override 173 public Attribute copy( final ConstantPool _constant_pool ) { 174 return (Attribute) clone(); 175 } 176 }