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 abstract class Attribute extends ClassFileEntry {
27
28 protected final CPUTF8 attributeName;
29
30 private int attributeNameIndex;
31
32 public Attribute(final CPUTF8 attributeName) {
33 this.attributeName = attributeName;
34 }
35
36 @Override
37 protected void doWrite(final DataOutputStream dos) throws IOException {
38 dos.writeShort(attributeNameIndex);
39 dos.writeInt(getLength());
40 writeBody(dos);
41 }
42
43 @Override
44 public boolean equals(final Object obj) {
45 if (this == obj) {
46 return true;
47 }
48 if (obj == null) {
49 return false;
50 }
51 if (this.getClass() != obj.getClass()) {
52 return false;
53 }
54 final Attribute other = (Attribute) obj;
55 if (!Objects.equals(attributeName, other.attributeName)) {
56 return false;
57 }
58 return true;
59 }
60
61 protected CPUTF8 getAttributeName() {
62 return attributeName;
63 }
64
65 protected abstract int getLength();
66
67
68
69
70
71
72
73 protected int getLengthIncludingHeader() {
74 return getLength() + 2 + 4;
75 }
76
77 @Override
78 protected ClassFileEntry[] getNestedClassFileEntries() {
79 return new ClassFileEntry[] { getAttributeName() };
80 }
81
82
83
84
85
86
87 public boolean hasBCIRenumbering() {
88 return false;
89 }
90
91 @Override
92 public int hashCode() {
93 return Objects.hash(attributeName);
94 }
95
96
97
98
99
100
101 public boolean isSourceFileAttribute() {
102 return false;
103 }
104
105 @Override
106 protected void resolve(final ClassConstantPool pool) {
107 super.resolve(pool);
108 attributeNameIndex = pool.indexOf(attributeName);
109 }
110
111 protected abstract void writeBody(DataOutputStream dos) throws IOException;
112
113 }