diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/FieldEntry.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/FieldEntry.java | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java index 0f1f506..c118ac0 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java | |||
| @@ -11,40 +11,29 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | ||
| 14 | import cuchaz.enigma.utils.Utils; | 15 | import cuchaz.enigma.utils.Utils; |
| 15 | 16 | ||
| 16 | public class FieldEntry implements Entry { | 17 | public class FieldEntry implements Entry { |
| 17 | 18 | ||
| 18 | private ClassEntry classEntry; | 19 | protected final ClassEntry ownerEntry; |
| 19 | private String name; | 20 | protected final String name; |
| 20 | private Type type; | 21 | protected final TypeDescriptor desc; |
| 21 | 22 | ||
| 22 | // NOTE: this argument order is important for the MethodReader/MethodWriter | 23 | // NOTE: this argument order is important for the MethodReader/MethodWriter |
| 23 | public FieldEntry(ClassEntry classEntry, String name, Type type) { | 24 | public FieldEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc) { |
| 24 | if (classEntry == null) { | 25 | Preconditions.checkNotNull(ownerEntry, "Owner cannot be null"); |
| 25 | throw new IllegalArgumentException("Class cannot be null!"); | 26 | Preconditions.checkNotNull(name, "Field name cannot be null"); |
| 26 | } | 27 | Preconditions.checkNotNull(desc, "Field descriptor cannot be null"); |
| 27 | if (name == null) { | ||
| 28 | throw new IllegalArgumentException("Field name cannot be null!"); | ||
| 29 | } | ||
| 30 | if (type == null) { | ||
| 31 | throw new IllegalArgumentException("Field type cannot be null!"); | ||
| 32 | } | ||
| 33 | 28 | ||
| 34 | this.classEntry = classEntry; | 29 | this.ownerEntry = ownerEntry; |
| 35 | this.name = name; | 30 | this.name = name; |
| 36 | this.type = type; | 31 | this.desc = desc; |
| 37 | } | ||
| 38 | |||
| 39 | public FieldEntry(FieldEntry other, ClassEntry newClassEntry) { | ||
| 40 | this.classEntry = newClassEntry; | ||
| 41 | this.name = other.name; | ||
| 42 | this.type = other.type; | ||
| 43 | } | 32 | } |
| 44 | 33 | ||
| 45 | @Override | 34 | @Override |
| 46 | public ClassEntry getClassEntry() { | 35 | public ClassEntry getOwnerClassEntry() { |
| 47 | return this.classEntry; | 36 | return this.ownerEntry; |
| 48 | } | 37 | } |
| 49 | 38 | ||
| 50 | @Override | 39 | @Override |
| @@ -54,21 +43,21 @@ public class FieldEntry implements Entry { | |||
| 54 | 43 | ||
| 55 | @Override | 44 | @Override |
| 56 | public String getClassName() { | 45 | public String getClassName() { |
| 57 | return this.classEntry.getName(); | 46 | return this.ownerEntry.getName(); |
| 58 | } | 47 | } |
| 59 | 48 | ||
| 60 | public Type getType() { | 49 | public TypeDescriptor getDesc() { |
| 61 | return this.type; | 50 | return this.desc; |
| 62 | } | 51 | } |
| 63 | 52 | ||
| 64 | @Override | 53 | @Override |
| 65 | public FieldEntry cloneToNewClass(ClassEntry classEntry) { | 54 | public FieldEntry updateOwnership(ClassEntry owner) { |
| 66 | return new FieldEntry(this, classEntry); | 55 | return new FieldEntry(owner, this.name, this.desc); |
| 67 | } | 56 | } |
| 68 | 57 | ||
| 69 | @Override | 58 | @Override |
| 70 | public int hashCode() { | 59 | public int hashCode() { |
| 71 | return Utils.combineHashesOrdered(this.classEntry, this.name, this.type); | 60 | return Utils.combineHashesOrdered(this.ownerEntry, this.name, this.desc); |
| 72 | } | 61 | } |
| 73 | 62 | ||
| 74 | @Override | 63 | @Override |
| @@ -77,11 +66,11 @@ public class FieldEntry implements Entry { | |||
| 77 | } | 66 | } |
| 78 | 67 | ||
| 79 | public boolean equals(FieldEntry other) { | 68 | public boolean equals(FieldEntry other) { |
| 80 | return this.classEntry.equals(other.classEntry) && this.name.equals(other.name) && this.type.equals(other.type); | 69 | return this.ownerEntry.equals(other.ownerEntry) && this.name.equals(other.name) && this.desc.equals(other.desc); |
| 81 | } | 70 | } |
| 82 | 71 | ||
| 83 | @Override | 72 | @Override |
| 84 | public String toString() { | 73 | public String toString() { |
| 85 | return this.classEntry.getName() + "." + this.name + ":" + this.type; | 74 | return this.ownerEntry.getName() + "." + this.name + ":" + this.desc; |
| 86 | } | 75 | } |
| 87 | } | 76 | } |