summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java
diff options
context:
space:
mode:
authorGravatar Thog2016-10-19 17:44:04 +0200
committerGravatar Thog2016-10-19 17:47:26 +0200
commit72115a6e4c83422b7359a9ae4d60badc244b55ff (patch)
tree6882be6d90bc1ebd5eb849f1a069b9eb5c07c247 /src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java
parentLocalVariableRenamer: Support correctly Nested Class constructors (Fix #49) (diff)
downloadenigma-fork-72115a6e4c83422b7359a9ae4d60badc244b55ff.tar.gz
enigma-fork-72115a6e4c83422b7359a9ae4d60badc244b55ff.tar.xz
enigma-fork-72115a6e4c83422b7359a9ae4d60badc244b55ff.zip
Starting implementing local variables (#33)
TODO: - Store format (need to be defined) - Implement some translate operations This commit also fix some cases where argument tokens are not selected
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java b/src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java
new file mode 100644
index 0000000..8bbaaaf
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java
@@ -0,0 +1,104 @@
1package cuchaz.enigma.mapping;
2
3import cuchaz.enigma.utils.Utils;
4
5/**
6 * Desc...
7 * Created by Thog
8 * 19/10/2016
9 */
10public class LocalVariableEntry implements Entry
11{
12
13 protected final BehaviorEntry behaviorEntry;
14 protected final String name;
15 protected final Type type;
16 protected final int index;
17
18 public LocalVariableEntry(BehaviorEntry behaviorEntry, int index, String name, Type type) {
19 if (behaviorEntry == null) {
20 throw new IllegalArgumentException("Behavior cannot be null!");
21 }
22 if (index < 0) {
23 throw new IllegalArgumentException("Index must be non-negative!");
24 }
25 if (name == null) {
26 throw new IllegalArgumentException("Variable name cannot be null!");
27 }
28 if (type == null) {
29 throw new IllegalArgumentException("Variable type cannot be null!");
30 }
31
32 this.behaviorEntry = behaviorEntry;
33 this.name = name;
34 this.type = type;
35 this.index = index;
36 }
37
38
39 public LocalVariableEntry(LocalVariableEntry other, ClassEntry newClassEntry) {
40 this.behaviorEntry = (BehaviorEntry) other.behaviorEntry.cloneToNewClass(newClassEntry);
41 this.name = other.name;
42 this.type = other.type;
43 this.index = other.index;
44 }
45
46 public BehaviorEntry getBehaviorEntry() {
47 return this.behaviorEntry;
48 }
49
50 public Type getType() {
51 return type;
52 }
53
54 public int getIndex() {
55 return index;
56 }
57
58 @Override
59 public String getName() {
60 return this.name;
61 }
62
63 @Override
64 public ClassEntry getClassEntry() {
65 return this.behaviorEntry.getClassEntry();
66 }
67
68 @Override
69 public String getClassName() {
70 return this.behaviorEntry.getClassName();
71 }
72
73 @Override
74 public LocalVariableEntry cloneToNewClass(ClassEntry classEntry) {
75 return new LocalVariableEntry(this, classEntry);
76 }
77
78 public String getMethodName() {
79 return this.behaviorEntry.getName();
80 }
81
82 public Signature getMethodSignature() {
83 return this.behaviorEntry.getSignature();
84 }
85
86 @Override
87 public int hashCode() {
88 return Utils.combineHashesOrdered(this.behaviorEntry, this.type.hashCode(), this.name.hashCode(), Integer.hashCode(this.index));
89 }
90
91 @Override
92 public boolean equals(Object other) {
93 return other instanceof LocalVariableEntry && equals((LocalVariableEntry) other);
94 }
95
96 public boolean equals(LocalVariableEntry other) {
97 return this.behaviorEntry.equals(other.behaviorEntry) && this.type.equals(other.type) && this.name.equals(other.name) && this.index == other.index;
98 }
99
100 @Override
101 public String toString() {
102 return this.behaviorEntry.toString() + "(" + this.index + ":" + this.name + ":" + this.type + ")";
103 }
104}