1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 package org.apache.bcel.classfile; 19 20 import java.io.DataInput; 21 import java.io.DataOutputStream; 22 import java.io.IOException; 23 24 import org.apache.bcel.Const; 25 26 /** 27 * This class is derived from the abstract {@link Constant} 28 * and represents a reference to a method type. 29 * 30 * @see Constant 31 * @since 6.0 32 */ 33 public final class ConstantMethodType extends Constant { 34 35 private int descriptor_index; 36 37 38 /** 39 * Initialize from another object. 40 */ 41 public ConstantMethodType(final ConstantMethodType c) { 42 this(c.getDescriptorIndex()); 43 } 44 45 46 /** 47 * Initialize instance from file data. 48 * 49 * @param file Input stream 50 * @throws IOException 51 */ 52 ConstantMethodType(final DataInput file) throws IOException { 53 this(file.readUnsignedShort()); 54 } 55 56 57 public ConstantMethodType(final int descriptor_index) { 58 super(Const.CONSTANT_MethodType); 59 this.descriptor_index = descriptor_index; 60 } 61 62 63 /** 64 * Called by objects that are traversing the nodes of the tree implicitly 65 * defined by the contents of a Java class. I.e., the hierarchy of methods, 66 * fields, attributes, etc. spawns a tree of objects. 67 * 68 * @param v Visitor object 69 */ 70 @Override 71 public void accept( final Visitor v ) { 72 v.visitConstantMethodType(this); 73 } 74 75 76 /** 77 * Dump name and signature index to file stream in binary format. 78 * 79 * @param file Output file stream 80 * @throws IOException 81 */ 82 @Override 83 public final void dump( final DataOutputStream file ) throws IOException { 84 file.writeByte(super.getTag()); 85 file.writeShort(descriptor_index); 86 } 87 88 89 public int getDescriptorIndex() { 90 return descriptor_index; 91 } 92 93 94 public void setDescriptorIndex(final int descriptor_index) { 95 this.descriptor_index = descriptor_index; 96 } 97 98 99 /** 100 * @return String representation 101 */ 102 @Override 103 public final String toString() { 104 return super.toString() + "(descriptor_index = " + descriptor_index + ")"; 105 } 106 } 107