1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package cuchaz.enigma.mapping.entry;
import com.google.common.base.Preconditions;
import cuchaz.enigma.mapping.TypeDescriptor;
import cuchaz.enigma.utils.Utils;
/**
* TypeDescriptor...
* Created by Thog
* 19/10/2016
*/
public class LocalVariableDefEntry extends LocalVariableEntry {
protected final MethodDefEntry ownerEntry;
protected final TypeDescriptor desc;
public LocalVariableDefEntry(MethodDefEntry ownerEntry, int index, String name, TypeDescriptor desc) {
super(ownerEntry, index, name);
Preconditions.checkNotNull(desc, "Variable desc cannot be null");
this.ownerEntry = ownerEntry;
this.desc = desc;
}
public LocalVariableDefEntry(MethodDefEntry ownerEntry, int index, String name) {
super(ownerEntry, index, name);
this.ownerEntry = ownerEntry;
int namedIndex = getNamedIndex();
if (namedIndex < 0) {
this.desc = TypeDescriptor.of(ownerEntry.getOwnerClassEntry().getName());
} else {
this.desc = ownerEntry.getDesc().getArgumentDescs().get(namedIndex);
}
}
@Override
public MethodDefEntry getOwnerEntry() {
return this.ownerEntry;
}
public TypeDescriptor getDesc() {
return desc;
}
public int getNamedIndex() {
// If we're not static, "this" is bound to index 0
int indexOffset = ownerEntry.getAccess().isStatic() ? 0 : 1;
return index - indexOffset;
}
@Override
public LocalVariableDefEntry updateOwnership(ClassEntry classEntry) {
return new LocalVariableDefEntry(ownerEntry.updateOwnership(classEntry), index, name, desc);
}
@Override
public int hashCode() {
return Utils.combineHashesOrdered(this.ownerEntry, this.desc.hashCode(), this.name.hashCode(), Integer.hashCode(this.index));
}
@Override
public boolean equals(Object other) {
return other instanceof LocalVariableDefEntry && equals((LocalVariableDefEntry) other);
}
public boolean equals(LocalVariableDefEntry other) {
return this.ownerEntry.equals(other.ownerEntry) && this.desc.equals(other.desc) && this.name.equals(other.name) && this.index == other.index;
}
@Override
public String toString() {
return this.ownerEntry + "(" + this.index + ":" + this.name + ":" + this.desc + ")";
}
}
|