author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.classfile; |
23 |
||
46174 | 24 |
import java.io.DataInput; |
25 |
import java.io.DataOutputStream; |
|
26 |
import java.io.IOException; |
|
6 | 27 |
|
46174 | 28 |
import com.sun.org.apache.bcel.internal.Const; |
6 | 29 |
|
30 |
/** |
|
46174 | 31 |
* This class is derived from the abstract {@link Constant} |
6 | 32 |
* and represents a reference to a (external) class. |
33 |
* |
|
46174 | 34 |
* @version $Id: ConstantClass.java 1749603 2016-06-21 20:50:19Z ggregory $ |
6 | 35 |
* @see Constant |
36 |
*/ |
|
37 |
public final class ConstantClass extends Constant implements ConstantObject { |
|
46174 | 38 |
|
39 |
private int name_index; // Identical to ConstantString except for the name |
|
40 |
||
6 | 41 |
|
46174 | 42 |
/** |
43 |
* Initialize from another object. |
|
44 |
*/ |
|
45 |
public ConstantClass(final ConstantClass c) { |
|
46 |
this(c.getNameIndex()); |
|
47 |
} |
|
6 | 48 |
|
49 |
||
46174 | 50 |
/** |
51 |
* Initialize instance from file data. |
|
52 |
* |
|
53 |
* @param file Input stream |
|
54 |
* @throws IOException |
|
55 |
*/ |
|
56 |
ConstantClass(final DataInput file) throws IOException { |
|
57 |
this(file.readUnsignedShort()); |
|
58 |
} |
|
6 | 59 |
|
46174 | 60 |
|
61 |
/** |
|
62 |
* @param name_index Name index in constant pool. Should refer to a |
|
63 |
* ConstantUtf8. |
|
64 |
*/ |
|
65 |
public ConstantClass(final int name_index) { |
|
66 |
super(Const.CONSTANT_Class); |
|
67 |
this.name_index = name_index; |
|
68 |
} |
|
69 |
||
6 | 70 |
|
46174 | 71 |
/** |
72 |
* Called by objects that are traversing the nodes of the tree implicitely |
|
73 |
* defined by the contents of a Java class. I.e., the hierarchy of methods, |
|
74 |
* fields, attributes, etc. spawns a tree of objects. |
|
75 |
* |
|
76 |
* @param v Visitor object |
|
77 |
*/ |
|
78 |
@Override |
|
79 |
public void accept( final Visitor v ) { |
|
80 |
v.visitConstantClass(this); |
|
81 |
} |
|
6 | 82 |
|
83 |
||
46174 | 84 |
/** |
85 |
* Dump constant class to file stream in binary format. |
|
86 |
* |
|
87 |
* @param file Output file stream |
|
88 |
* @throws IOException |
|
89 |
*/ |
|
90 |
@Override |
|
91 |
public final void dump( final DataOutputStream file ) throws IOException { |
|
92 |
file.writeByte(super.getTag()); |
|
93 |
file.writeShort(name_index); |
|
94 |
} |
|
95 |
||
96 |
||
97 |
/** |
|
98 |
* @return Name index in constant pool of class name. |
|
99 |
*/ |
|
100 |
public final int getNameIndex() { |
|
101 |
return name_index; |
|
102 |
} |
|
103 |
||
6 | 104 |
|
46174 | 105 |
/** |
106 |
* @param name_index the name index in the constant pool of this Constant Class |
|
107 |
*/ |
|
108 |
public final void setNameIndex( final int name_index ) { |
|
109 |
this.name_index = name_index; |
|
110 |
} |
|
111 |
||
112 |
||
113 |
/** @return String object |
|
114 |
*/ |
|
115 |
@Override |
|
116 |
public Object getConstantValue( final ConstantPool cp ) { |
|
117 |
final Constant c = cp.getConstant(name_index, Const.CONSTANT_Utf8); |
|
118 |
return ((ConstantUtf8) c).getBytes(); |
|
119 |
} |
|
6 | 120 |
|
46174 | 121 |
|
122 |
/** @return dereferenced string |
|
123 |
*/ |
|
124 |
public String getBytes( final ConstantPool cp ) { |
|
125 |
return (String) getConstantValue(cp); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
/** |
|
130 |
* @return String representation. |
|
131 |
*/ |
|
132 |
@Override |
|
133 |
public final String toString() { |
|
134 |
return super.toString() + "(name_index = " + name_index + ")"; |
|
135 |
} |
|
6 | 136 |
} |