summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/MethodEntry.java
blob: 9c3058c47059bfe76107050dddcf184ae2cc960e (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
/*******************************************************************************
 * Copyright (c) 2015 Jeff Martin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public
 * License v3.0 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Contributors:
 * Jeff Martin - initial API and implementation
 ******************************************************************************/

package cuchaz.enigma.mapping;

import cuchaz.enigma.utils.Utils;

public class MethodEntry implements BehaviorEntry {

	private ClassEntry classEntry;
	private String name;
	private Signature signature;

	public MethodEntry(ClassEntry classEntry, String name, Signature signature) {
		if (classEntry == null) {
			throw new IllegalArgumentException("Class cannot be null!");
		}
		if (name == null) {
			throw new IllegalArgumentException("Method name cannot be null!");
		}
		if (signature == null) {
			throw new IllegalArgumentException("Method signature cannot be null!");
		}
		if (name.startsWith("<")) {
			throw new IllegalArgumentException("Don't use MethodEntry for a constructor!");
		}

		this.classEntry = classEntry;
		this.name = name;
		this.signature = signature;
	}

	public MethodEntry(MethodEntry other, String newClassName) {
		this.classEntry = new ClassEntry(newClassName);
		this.name = other.name;
		this.signature = other.signature;
	}

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

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

	@Override
	public Signature getSignature() {
		return this.signature;
	}

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

	@Override
	public MethodEntry cloneToNewClass(ClassEntry classEntry) {
		return new MethodEntry(this, classEntry.getName());
	}

	@Override
	public int hashCode() {
		return Utils.combineHashesOrdered(this.classEntry, this.name, this.signature);
	}

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

	public boolean equals(MethodEntry other) {
		return this.classEntry.equals(other.classEntry) && this.name.equals(other.name) && this.signature.equals(other.signature);
	}

	@Override
	public String toString() {
		return this.classEntry.getName() + "." + this.name + this.signature;
	}
}