1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 */ |
3 */ |
4 /* |
4 /* |
5 * Licensed to the Apache Software Foundation (ASF) under one or more |
5 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * contributor license agreements. See the NOTICE file distributed with |
6 * contributor license agreements. See the NOTICE file distributed with |
7 * this work for additional information regarding copyright ownership. |
7 * this work for additional information regarding copyright ownership. |
25 |
25 |
26 import com.sun.org.apache.bcel.internal.Const; |
26 import com.sun.org.apache.bcel.internal.Const; |
27 |
27 |
28 /** |
28 /** |
29 * Abstract super class for Fieldref, Methodref, InterfaceMethodref and |
29 * Abstract super class for Fieldref, Methodref, InterfaceMethodref and |
30 * InvokeDynamic constants. |
30 * InvokeDynamic constants. |
31 * |
31 * |
32 * @version $Id: ConstantCP.java 1747278 2016-06-07 17:28:43Z britter $ |
32 * @version $Id$ |
33 * @see ConstantFieldref |
33 * @see ConstantFieldref |
34 * @see ConstantMethodref |
34 * @see ConstantMethodref |
35 * @see ConstantInterfaceMethodref |
35 * @see ConstantInterfaceMethodref |
36 * @see ConstantInvokeDynamic |
36 * @see ConstantInvokeDynamic |
|
37 * @LastModified: Jun 2019 |
37 */ |
38 */ |
38 public abstract class ConstantCP extends Constant { |
39 public abstract class ConstantCP extends Constant { |
39 |
40 |
40 /** |
41 /** |
41 * References to the constants containing the class and the field signature |
42 * References to the constants containing the class and the field signature |
51 */ |
52 */ |
52 public ConstantCP(final ConstantCP c) { |
53 public ConstantCP(final ConstantCP c) { |
53 this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); |
54 this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); |
54 } |
55 } |
55 |
56 |
|
57 |
56 /** |
58 /** |
57 * Initialize instance from file data. |
59 * Initialize instance from file data. |
58 * |
60 * |
59 * @param tag Constant type tag |
61 * @param tag Constant type tag |
60 * @param file Input stream |
62 * @param file Input stream |
61 * @throws IOException |
63 * @throws IOException |
62 */ |
64 */ |
63 ConstantCP(final byte tag, final DataInput file) throws IOException { |
65 ConstantCP(final byte tag, final DataInput file) throws IOException { |
64 this(tag, file.readUnsignedShort(), file.readUnsignedShort()); |
66 this(tag, file.readUnsignedShort(), file.readUnsignedShort()); |
65 } |
67 } |
|
68 |
66 |
69 |
67 /** |
70 /** |
68 * @param class_index Reference to the class containing the field |
71 * @param class_index Reference to the class containing the field |
69 * @param name_and_type_index and the field signature |
72 * @param name_and_type_index and the field signature |
70 */ |
73 */ |
72 super(tag); |
75 super(tag); |
73 this.class_index = class_index; |
76 this.class_index = class_index; |
74 this.name_and_type_index = name_and_type_index; |
77 this.name_and_type_index = name_and_type_index; |
75 } |
78 } |
76 |
79 |
|
80 |
77 /** |
81 /** |
78 * Dump constant field reference to file stream in binary format. |
82 * Dump constant field reference to file stream in binary format. |
79 * |
83 * |
80 * @param file Output file stream |
84 * @param file Output file stream |
81 * @throws IOException |
85 * @throws IOException |
82 */ |
86 */ |
83 @Override |
87 @Override |
84 public final void dump(final DataOutputStream file) throws IOException { |
88 public final void dump( final DataOutputStream file ) throws IOException { |
85 file.writeByte(super.getTag()); |
89 file.writeByte(super.getTag()); |
86 file.writeShort(class_index); |
90 file.writeShort(class_index); |
87 file.writeShort(name_and_type_index); |
91 file.writeShort(name_and_type_index); |
88 } |
92 } |
|
93 |
89 |
94 |
90 /** |
95 /** |
91 * @return Reference (index) to class this constant refers to. |
96 * @return Reference (index) to class this constant refers to. |
92 */ |
97 */ |
93 public final int getClassIndex() { |
98 public final int getClassIndex() { |
94 return class_index; |
99 return class_index; |
95 } |
100 } |
96 |
101 |
|
102 |
97 /** |
103 /** |
98 * @param class_index points to Constant_class |
104 * @param class_index points to Constant_class |
99 */ |
105 */ |
100 public final void setClassIndex(final int class_index) { |
106 public final void setClassIndex( final int class_index ) { |
101 this.class_index = class_index; |
107 this.class_index = class_index; |
102 } |
108 } |
|
109 |
103 |
110 |
104 /** |
111 /** |
105 * @return Reference (index) to signature of the field. |
112 * @return Reference (index) to signature of the field. |
106 */ |
113 */ |
107 public final int getNameAndTypeIndex() { |
114 public final int getNameAndTypeIndex() { |
108 return name_and_type_index; |
115 return name_and_type_index; |
109 } |
116 } |
110 |
117 |
|
118 |
111 /** |
119 /** |
112 * @param name_and_type_index points to Constant_NameAndType |
120 * @param name_and_type_index points to Constant_NameAndType |
113 */ |
121 */ |
114 public final void setNameAndTypeIndex(final int name_and_type_index) { |
122 public final void setNameAndTypeIndex( final int name_and_type_index ) { |
115 this.name_and_type_index = name_and_type_index; |
123 this.name_and_type_index = name_and_type_index; |
116 } |
124 } |
|
125 |
117 |
126 |
118 /** |
127 /** |
119 * @return Class this field belongs to. |
128 * @return Class this field belongs to. |
120 */ |
129 */ |
121 public String getClass(final ConstantPool cp) { |
130 public String getClass( final ConstantPool cp ) { |
122 return cp.constantToString(class_index, Const.CONSTANT_Class); |
131 return cp.constantToString(class_index, Const.CONSTANT_Class); |
123 } |
132 } |
|
133 |
124 |
134 |
125 /** |
135 /** |
126 * @return String representation. |
136 * @return String representation. |
127 * |
137 * |
128 * not final as ConstantInvokeDynamic needs to modify |
138 * not final as ConstantInvokeDynamic needs to modify |