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 SourceFileAttribute extends Attribute {
23: private CPUTF8 name;
24:
25: private int nameIndex;
26:
27: public SourceFileAttribute(String name) {
28: super ("SourceFile"); //$NON-NLS-1$
29: this .name = new CPUTF8(name,
30: ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
31: }
32:
33: public boolean equals(Object obj) {
34: if (this == obj)
35: return true;
36: if (!super .equals(obj))
37: return false;
38: if (this .getClass() != obj.getClass())
39: return false;
40: final SourceFileAttribute other = (SourceFileAttribute) obj;
41: if (name == null) {
42: if (other.name != null)
43: return false;
44: } else if (!name.equals(other.name))
45: return false;
46: return true;
47: }
48:
49: protected int getLength() {
50: return 2;
51: }
52:
53: protected ClassFileEntry[] getNestedClassFileEntries() {
54: return new ClassFileEntry[] { getAttributeName(), name };
55: }
56:
57: public int hashCode() {
58: final int PRIME = 31;
59: int result = super .hashCode();
60: result = PRIME * result
61: + ((name == null) ? 0 : name.hashCode());
62: return result;
63: }
64:
65: protected void resolve(ClassConstantPool pool) {
66: super .resolve(pool);
67: nameIndex = pool.indexOf(name);
68: }
69:
70: public String toString() {
71: return "SourceFile: " + name;
72: }
73:
74: protected void writeBody(DataOutputStream dos) throws IOException {
75: dos.writeShort(nameIndex);
76: }
77: }
|