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