1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.harmony.unpack200.bytecode;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.util.Objects;
22
23
24
25
26 public class SourceFileAttribute extends Attribute {
27
28 private static CPUTF8 attributeName;
29
30 public static void setAttributeName(final CPUTF8 cpUTF8Value) {
31 attributeName = cpUTF8Value;
32 }
33
34 private final CPUTF8 name;
35
36 private int nameIndex;
37
38 public SourceFileAttribute(final CPUTF8 name) {
39 super(attributeName);
40 this.name = name;
41 }
42
43 @Override
44 public boolean equals(final Object obj) {
45 if (this == obj) {
46 return true;
47 }
48 if (!super.equals(obj)) {
49 return false;
50 }
51 if (this.getClass() != obj.getClass()) {
52 return false;
53 }
54 final SourceFileAttribute other = (SourceFileAttribute) obj;
55 return Objects.equals(name, other.name);
56 }
57
58 @Override
59 protected int getLength() {
60 return 2;
61 }
62
63 @Override
64 protected ClassFileEntry[] getNestedClassFileEntries() {
65 return new ClassFileEntry[] { getAttributeName(), name };
66 }
67
68 @Override
69 public int hashCode() {
70 final int PRIME = 31;
71 int result = super.hashCode();
72 result = PRIME * result + (name == null ? 0 : name.hashCode());
73 return result;
74 }
75
76
77
78
79
80
81 @Override
82 public boolean isSourceFileAttribute() {
83 return true;
84 }
85
86 @Override
87 protected void resolve(final ClassConstantPool pool) {
88 super.resolve(pool);
89 nameIndex = pool.indexOf(name);
90 }
91
92 @Override
93 public String toString() {
94 return "SourceFile: " + name;
95 }
96
97 @Override
98 protected void writeBody(final DataOutputStream dos) throws IOException {
99 dos.writeShort(nameIndex);
100 }
101 }