summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java
new file mode 100644
index 00000000..bb7c85eb
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java
@@ -0,0 +1,54 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.mapping.entry;
13
14import com.google.common.base.Preconditions;
15import cuchaz.enigma.bytecode.AccessFlags;
16import cuchaz.enigma.mapping.MethodDescriptor;
17import cuchaz.enigma.mapping.Signature;
18
19public class MethodDefEntry extends MethodEntry {
20
21 private final AccessFlags access;
22 private final Signature signature;
23
24 public MethodDefEntry(ClassEntry classEntry, String name, MethodDescriptor descriptor, Signature signature, AccessFlags access) {
25 super(classEntry, name, descriptor);
26 Preconditions.checkNotNull(access, "Method access cannot be null");
27 Preconditions.checkNotNull(signature, "Method signature cannot be null");
28 this.access = access;
29 this.signature = signature;
30 }
31
32 public AccessFlags getAccess() {
33 return access;
34 }
35
36 public Signature getSignature() {
37 return signature;
38 }
39
40 public int getVariableOffset(ClassDefEntry ownerEntry) {
41 // Enum constructors have an implicit "name" and "ordinal" parameter as well as "this"
42 if (ownerEntry.getAccess().isEnum() && getName().startsWith("<")) {
43 return 3;
44 } else {
45 // If we're not static, "this" is bound to index 0
46 return getAccess().isStatic() ? 0 : 1;
47 }
48 }
49
50 @Override
51 public MethodDefEntry updateOwnership(ClassEntry classEntry) {
52 return new MethodDefEntry(new ClassEntry(classEntry.getName()), name, descriptor, signature, access);
53 }
54}