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 the abstract {@link Constant}
32  * and represents a reference to a method type.
33  *
34  * @see     Constant
35  * @since 6.0
36  */
37 public final class ConstantMethodType extends Constant {
38 
39     private int descriptor_index;
40 
41 
42     /**
43      * Initialize from another object.
44      */
ConstantMethodType(final ConstantMethodType c)45     public ConstantMethodType(final ConstantMethodType c) {
46         this(c.getDescriptorIndex());
47     }
48 
49 
50     /**
51      * Initialize instance from file data.
52      *
53      * @param file Input stream
54      * @throws IOException
55      */
ConstantMethodType(final DataInput file)56     ConstantMethodType(final DataInput file) throws IOException {
57         this(file.readUnsignedShort());
58     }
59 
60 
ConstantMethodType(final int descriptor_index)61     public ConstantMethodType(final int descriptor_index) {
62         super(Const.CONSTANT_MethodType);
63         this.descriptor_index = descriptor_index;
64     }
65 
66 
67     /**
68      * Called by objects that are traversing the nodes of the tree implicitly
69      * defined by the contents of a Java class. I.e., the hierarchy of methods,
70      * fields, attributes, etc. spawns a tree of objects.
71      *
72      * @param v Visitor object
73      */
74     @Override
accept( final Visitor v )75     public void accept( final Visitor v ) {
76         v.visitConstantMethodType(this);
77     }
78 
79 
80     /**
81      * Dump name and signature index to file stream in binary format.
82      *
83      * @param file Output file stream
84      * @throws IOException
85      */
86     @Override
dump( final DataOutputStream file )87     public void dump( final DataOutputStream file ) throws IOException {
88         file.writeByte(super.getTag());
89         file.writeShort(descriptor_index);
90     }
91 
92 
getDescriptorIndex()93     public int getDescriptorIndex() {
94         return descriptor_index;
95     }
96 
97 
setDescriptorIndex(final int descriptor_index)98     public void setDescriptorIndex(final int descriptor_index) {
99         this.descriptor_index = descriptor_index;
100     }
101 
102 
103     /**
104      * @return String representation
105      */
106     @Override
toString()107     public String toString() {
108         return super.toString() + "(descriptor_index = " + descriptor_index + ")";
109     }
110 }
111