summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/LocalVariableEntry.java
blob: 2bb5e3f7a7a11ed4201bfebce3fed4579a5e76e4 (plain) (blame)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cuchaz.enigma.mapping;

import cuchaz.enigma.utils.Utils;

/**
 * Desc...
 * Created by Thog
 * 19/10/2016
 */
public class LocalVariableEntry implements Entry {

	protected final BehaviorEntry behaviorEntry;
	protected final String name;
	protected final Type type;
	protected final int index;

	public LocalVariableEntry(BehaviorEntry behaviorEntry, int index, String name, Type type) {
		if (behaviorEntry == null) {
			throw new IllegalArgumentException("Behavior cannot be null!");
		}
		if (index < 0) {
			throw new IllegalArgumentException("Index must be non-negative!");
		}
		if (name == null) {
			throw new IllegalArgumentException("Variable name cannot be null!");
		}
		if (type == null) {
			throw new IllegalArgumentException("Variable type cannot be null!");
		}

		this.behaviorEntry = behaviorEntry;
		this.name = name;
		this.type = type;
		this.index = index;
	}

	public LocalVariableEntry(LocalVariableEntry other, ClassEntry newClassEntry) {
		this.behaviorEntry = (BehaviorEntry) other.behaviorEntry.cloneToNewClass(newClassEntry);
		this.name = other.name;
		this.type = other.type;
		this.index = other.index;
	}

	public BehaviorEntry getBehaviorEntry() {
		return this.behaviorEntry;
	}

	public Type getType() {
		return type;
	}

	public int getIndex() {
		return index;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public ClassEntry getClassEntry() {
		return this.behaviorEntry.getClassEntry();
	}

	@Override
	public String getClassName() {
		return this.behaviorEntry.getClassName();
	}

	@Override
	public LocalVariableEntry cloneToNewClass(ClassEntry classEntry) {
		return new LocalVariableEntry(this, classEntry);
	}

	public String getMethodName() {
		return this.behaviorEntry.getName();
	}

	public Signature getMethodSignature() {
		return this.behaviorEntry.getSignature();
	}

	@Override
	public int hashCode() {
		return Utils.combineHashesOrdered(this.behaviorEntry, this.type.hashCode(), this.name.hashCode(), Integer.hashCode(this.index));
	}

	@Override
	public boolean equals(Object other) {
		return other instanceof LocalVariableEntry && equals((LocalVariableEntry) other);
	}

	public boolean equals(LocalVariableEntry other) {
		return this.behaviorEntry.equals(other.behaviorEntry) && this.type.equals(other.type) && this.name.equals(other.name) && this.index == other.index;
	}

	@Override
	public String toString() {
		return this.behaviorEntry + "(" + this.index + ":" + this.name + ":" + this.type + ")";
	}
}