01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.harmony.pack200.bytecode;
18:
19: import java.io.DataOutputStream;
20: import java.io.IOException;
21:
22: public class CPClass extends ConstantPoolEntry {
23: private int index;
24:
25: public String name;
26:
27: private CPUTF8 utf8;
28:
29: public CPClass(String name) {
30: super (ConstantPoolEntry.CP_Class);
31: this .name = name;
32: this .domain = ClassConstantPool.DOMAIN_CLASSREF;
33: this .utf8 = new CPUTF8(name,
34: ClassConstantPool.DOMAIN_NORMALASCIIZ);
35: }
36:
37: public boolean equals(Object obj) {
38: if (this == obj)
39: return true;
40: if (obj == null)
41: return false;
42: if (this .getClass() != obj.getClass())
43: return false;
44: final CPClass other = (CPClass) obj;
45: if (name == null) {
46: if (other.name != null)
47: return false;
48: } else if (!name.equals(other.name))
49: return false;
50: if (utf8 == null) {
51: if (other.utf8 != null)
52: return false;
53: } else if (!utf8.equals(other.utf8))
54: return false;
55: return true;
56: }
57:
58: protected ClassFileEntry[] getNestedClassFileEntries() {
59: return new ClassFileEntry[] { utf8, };
60: }
61:
62: public int hashCode() {
63: final int PRIME = 31;
64: int result = 1;
65: result = PRIME * result
66: + ((name == null) ? 0 : name.hashCode());
67: result = PRIME * result
68: + ((utf8 == null) ? 0 : utf8.hashCode());
69: return result;
70: }
71:
72: protected void resolve(ClassConstantPool pool) {
73: super .resolve(pool);
74: index = pool.indexOf(utf8);
75: }
76:
77: public String toString() {
78: return "Class: " + getName();
79: }
80:
81: public String getName() {
82: return name;
83: }
84:
85: protected void writeBody(DataOutputStream dos) throws IOException {
86: dos.writeShort(index);
87: }
88:
89: public String comparisonString() {
90: // TODO: what to do about inner classes?
91: if (name == null) {
92: return "null:name (probably an inner class?)";
93: }
94: ;
95: return getName();
96: }
97:
98: }
|