diff options
| author | 2018-05-19 17:06:26 +0200 | |
|---|---|---|
| committer | 2018-05-19 17:06:26 +0200 | |
| commit | 406b9a89318473571d27de60b8aa1b51f84af245 (patch) | |
| tree | 4be0066dfe09eb98cd337779d8f759334276a18c /src/main/java/cuchaz/enigma/mapping/entry | |
| parent | Initial port to ASM (diff) | |
| download | enigma-fork-406b9a89318473571d27de60b8aa1b51f84af245.tar.gz enigma-fork-406b9a89318473571d27de60b8aa1b51f84af245.tar.xz enigma-fork-406b9a89318473571d27de60b8aa1b51f84af245.zip | |
Package updates
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/entry')
12 files changed, 781 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java new file mode 100644 index 0000000..75e7f1b --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java | |||
| @@ -0,0 +1,29 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 16 | |||
| 17 | public class ClassDefEntry extends ClassEntry { | ||
| 18 | private final AccessFlags access; | ||
| 19 | |||
| 20 | public ClassDefEntry(String className, AccessFlags access) { | ||
| 21 | super(className); | ||
| 22 | Preconditions.checkNotNull(access, "Class access cannot be null"); | ||
| 23 | this.access = access; | ||
| 24 | } | ||
| 25 | |||
| 26 | public AccessFlags getAccess() { | ||
| 27 | return access; | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java new file mode 100644 index 0000000..fc604d8 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java | |||
| @@ -0,0 +1,171 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import com.google.common.collect.Lists; | ||
| 16 | |||
| 17 | import java.util.List; | ||
| 18 | |||
| 19 | public class ClassEntry implements Entry { | ||
| 20 | |||
| 21 | private final String name; | ||
| 22 | |||
| 23 | public ClassEntry(String className) { | ||
| 24 | Preconditions.checkNotNull(className, "Class name cannot be null"); | ||
| 25 | |||
| 26 | if (className.indexOf('.') >= 0) { | ||
| 27 | throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); | ||
| 28 | } | ||
| 29 | |||
| 30 | this.name = className; | ||
| 31 | |||
| 32 | if (isInnerClass() && getInnermostClassName().indexOf('/') >= 0) { | ||
| 33 | throw new IllegalArgumentException("Inner class must not have a package: " + className); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public ClassEntry(ClassEntry other) { | ||
| 38 | this.name = other.name; | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public String getName() { | ||
| 43 | return this.name; | ||
| 44 | } | ||
| 45 | |||
| 46 | @Override | ||
| 47 | public String getClassName() { | ||
| 48 | return this.name; | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public ClassEntry getOwnerClassEntry() { | ||
| 53 | return this; | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | public ClassEntry updateOwnership(ClassEntry classEntry) { | ||
| 58 | return classEntry; | ||
| 59 | } | ||
| 60 | |||
| 61 | @Override | ||
| 62 | public int hashCode() { | ||
| 63 | return this.name.hashCode(); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Override | ||
| 67 | public boolean equals(Object other) { | ||
| 68 | return other instanceof ClassEntry && equals((ClassEntry) other); | ||
| 69 | } | ||
| 70 | |||
| 71 | public boolean equals(ClassEntry other) { | ||
| 72 | return other != null && this.name.equals(other.name); | ||
| 73 | } | ||
| 74 | |||
| 75 | @Override | ||
| 76 | public String toString() { | ||
| 77 | return this.name; | ||
| 78 | } | ||
| 79 | |||
| 80 | public boolean isInnerClass() { | ||
| 81 | return this.name.lastIndexOf('$') >= 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | public List<String> getClassChainNames() { | ||
| 85 | return Lists.newArrayList(this.name.split("\\$")); | ||
| 86 | } | ||
| 87 | |||
| 88 | public List<ClassEntry> getClassChain() { | ||
| 89 | List<ClassEntry> entries = Lists.newArrayList(); | ||
| 90 | StringBuilder buf = new StringBuilder(); | ||
| 91 | for (String name : getClassChainNames()) { | ||
| 92 | if (buf.length() > 0) { | ||
| 93 | buf.append("$"); | ||
| 94 | } | ||
| 95 | buf.append(name); | ||
| 96 | entries.add(new ClassEntry(buf.toString())); | ||
| 97 | } | ||
| 98 | return entries; | ||
| 99 | } | ||
| 100 | |||
| 101 | public String getOutermostClassName() { | ||
| 102 | if (isInnerClass()) { | ||
| 103 | return this.name.substring(0, this.name.indexOf('$')); | ||
| 104 | } | ||
| 105 | return this.name; | ||
| 106 | } | ||
| 107 | |||
| 108 | public ClassEntry getOutermostClassEntry() { | ||
| 109 | return new ClassEntry(getOutermostClassName()); | ||
| 110 | } | ||
| 111 | |||
| 112 | public String getOuterClassName() { | ||
| 113 | if (!isInnerClass()) { | ||
| 114 | throw new Error("This is not an inner class!"); | ||
| 115 | } | ||
| 116 | return this.name.substring(0, this.name.lastIndexOf('$')); | ||
| 117 | } | ||
| 118 | |||
| 119 | public ClassEntry getOuterClassEntry() { | ||
| 120 | return new ClassEntry(getOuterClassName()); | ||
| 121 | } | ||
| 122 | |||
| 123 | public String getInnermostClassName() { | ||
| 124 | if (!isInnerClass()) { | ||
| 125 | throw new Error("This is not an inner class!"); | ||
| 126 | } | ||
| 127 | return this.name.substring(this.name.lastIndexOf('$') + 1); | ||
| 128 | } | ||
| 129 | |||
| 130 | public boolean isInDefaultPackage() { | ||
| 131 | return this.name.indexOf('/') < 0; | ||
| 132 | } | ||
| 133 | |||
| 134 | public String getPackageName() { | ||
| 135 | return getPackageName(this.name); | ||
| 136 | } | ||
| 137 | |||
| 138 | public String getSimpleName() { | ||
| 139 | int pos = this.name.lastIndexOf('/'); | ||
| 140 | if (pos > 0) { | ||
| 141 | return this.name.substring(pos + 1); | ||
| 142 | } | ||
| 143 | return this.name; | ||
| 144 | } | ||
| 145 | |||
| 146 | public static String getPackageName(String name) { | ||
| 147 | int pos = name.lastIndexOf('/'); | ||
| 148 | if (pos > 0) { | ||
| 149 | return name.substring(0, pos); | ||
| 150 | } | ||
| 151 | return null; | ||
| 152 | } | ||
| 153 | |||
| 154 | public ClassEntry buildClassEntry(List<ClassEntry> classChain) { | ||
| 155 | assert (classChain.contains(this)); | ||
| 156 | StringBuilder buf = new StringBuilder(); | ||
| 157 | for (ClassEntry chainEntry : classChain) { | ||
| 158 | if (buf.length() == 0) { | ||
| 159 | buf.append(chainEntry.getName()); | ||
| 160 | } else { | ||
| 161 | buf.append("$"); | ||
| 162 | buf.append(chainEntry.isInnerClass() ? chainEntry.getInnermostClassName() : chainEntry.getSimpleName()); | ||
| 163 | } | ||
| 164 | |||
| 165 | if (chainEntry == this) { | ||
| 166 | break; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | return new ClassEntry(buf.toString()); | ||
| 170 | } | ||
| 171 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/Entry.java b/src/main/java/cuchaz/enigma/mapping/entry/Entry.java new file mode 100644 index 0000000..b612140 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/Entry.java | |||
| @@ -0,0 +1,22 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | public interface Entry { | ||
| 15 | String getName(); | ||
| 16 | |||
| 17 | String getClassName(); | ||
| 18 | |||
| 19 | ClassEntry getOwnerClassEntry(); | ||
| 20 | |||
| 21 | Entry updateOwnership(ClassEntry classEntry); | ||
| 22 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/EntryFactory.java b/src/main/java/cuchaz/enigma/mapping/entry/EntryFactory.java new file mode 100644 index 0000000..5bd159f --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/EntryFactory.java | |||
| @@ -0,0 +1,49 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.JarIndex; | ||
| 15 | import cuchaz.enigma.mapping.ClassMapping; | ||
| 16 | import cuchaz.enigma.mapping.FieldMapping; | ||
| 17 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 18 | import cuchaz.enigma.mapping.MethodMapping; | ||
| 19 | |||
| 20 | public class EntryFactory { | ||
| 21 | public static ClassEntry getObfClassEntry(JarIndex jarIndex, ClassMapping classMapping) { | ||
| 22 | ClassEntry obfClassEntry = new ClassEntry(classMapping.getObfFullName()); | ||
| 23 | return obfClassEntry.buildClassEntry(jarIndex.getObfClassChain(obfClassEntry)); | ||
| 24 | } | ||
| 25 | |||
| 26 | private static ClassEntry getObfClassEntry(ClassMapping classMapping) { | ||
| 27 | return new ClassEntry(classMapping.getObfFullName()); | ||
| 28 | } | ||
| 29 | |||
| 30 | public static ClassEntry getDeobfClassEntry(ClassMapping classMapping) { | ||
| 31 | return new ClassEntry(classMapping.getDeobfName()); | ||
| 32 | } | ||
| 33 | |||
| 34 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { | ||
| 35 | return new FieldEntry(getObfClassEntry(classMapping), fieldMapping.getObfName(), fieldMapping.getObfDesc()); | ||
| 36 | } | ||
| 37 | |||
| 38 | public static MethodEntry getMethodEntry(ClassEntry classEntry, String name, MethodDescriptor desc) { | ||
| 39 | return new MethodEntry(classEntry, name, desc); | ||
| 40 | } | ||
| 41 | |||
| 42 | public static MethodEntry getObfMethodEntry(ClassEntry classEntry, MethodMapping methodMapping) { | ||
| 43 | return getMethodEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfDesc()); | ||
| 44 | } | ||
| 45 | |||
| 46 | public static MethodEntry getObfMethodEntry(ClassMapping classMapping, MethodMapping methodMapping) { | ||
| 47 | return getObfMethodEntry(getObfClassEntry(classMapping), methodMapping); | ||
| 48 | } | ||
| 49 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java new file mode 100644 index 0000000..78ea5f7 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java | |||
| @@ -0,0 +1,35 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 16 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 17 | |||
| 18 | public class FieldDefEntry extends FieldEntry { | ||
| 19 | private final AccessFlags access; | ||
| 20 | |||
| 21 | public FieldDefEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc, AccessFlags access) { | ||
| 22 | super(ownerEntry, name, desc); | ||
| 23 | Preconditions.checkNotNull(access, "Field access cannot be null"); | ||
| 24 | this.access = access; | ||
| 25 | } | ||
| 26 | |||
| 27 | public AccessFlags getAccess() { | ||
| 28 | return access; | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | public FieldDefEntry updateOwnership(ClassEntry owner) { | ||
| 33 | return new FieldDefEntry(owner, this.name, this.desc, access); | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java new file mode 100644 index 0000000..b6e1554 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java | |||
| @@ -0,0 +1,77 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 16 | import cuchaz.enigma.utils.Utils; | ||
| 17 | |||
| 18 | public class FieldEntry implements Entry { | ||
| 19 | |||
| 20 | protected final ClassEntry ownerEntry; | ||
| 21 | protected final String name; | ||
| 22 | protected final TypeDescriptor desc; | ||
| 23 | |||
| 24 | // NOTE: this argument order is important for the MethodReader/MethodWriter | ||
| 25 | public FieldEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc) { | ||
| 26 | Preconditions.checkNotNull(ownerEntry, "Owner cannot be null"); | ||
| 27 | Preconditions.checkNotNull(name, "Field name cannot be null"); | ||
| 28 | Preconditions.checkNotNull(desc, "Field descriptor cannot be null"); | ||
| 29 | |||
| 30 | this.ownerEntry = ownerEntry; | ||
| 31 | this.name = name; | ||
| 32 | this.desc = desc; | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public ClassEntry getOwnerClassEntry() { | ||
| 37 | return this.ownerEntry; | ||
| 38 | } | ||
| 39 | |||
| 40 | @Override | ||
| 41 | public String getName() { | ||
| 42 | return this.name; | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public String getClassName() { | ||
| 47 | return this.ownerEntry.getName(); | ||
| 48 | } | ||
| 49 | |||
| 50 | public TypeDescriptor getDesc() { | ||
| 51 | return this.desc; | ||
| 52 | } | ||
| 53 | |||
| 54 | @Override | ||
| 55 | public FieldEntry updateOwnership(ClassEntry owner) { | ||
| 56 | return new FieldEntry(owner, this.name, this.desc); | ||
| 57 | } | ||
| 58 | |||
| 59 | @Override | ||
| 60 | public int hashCode() { | ||
| 61 | return Utils.combineHashesOrdered(this.ownerEntry, this.name, this.desc); | ||
| 62 | } | ||
| 63 | |||
| 64 | @Override | ||
| 65 | public boolean equals(Object other) { | ||
| 66 | return other instanceof FieldEntry && equals((FieldEntry) other); | ||
| 67 | } | ||
| 68 | |||
| 69 | public boolean equals(FieldEntry other) { | ||
| 70 | return this.ownerEntry.equals(other.ownerEntry) && this.name.equals(other.name) && this.desc.equals(other.desc); | ||
| 71 | } | ||
| 72 | |||
| 73 | @Override | ||
| 74 | public String toString() { | ||
| 75 | return this.ownerEntry.getName() + "." + this.name + ":" + this.desc; | ||
| 76 | } | ||
| 77 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableDefEntry.java new file mode 100644 index 0000000..0c4f3c1 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableDefEntry.java | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | package cuchaz.enigma.mapping.entry; | ||
| 2 | |||
| 3 | import com.google.common.base.Preconditions; | ||
| 4 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 5 | import cuchaz.enigma.utils.Utils; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * TypeDescriptor... | ||
| 9 | * Created by Thog | ||
| 10 | * 19/10/2016 | ||
| 11 | */ | ||
| 12 | public class LocalVariableDefEntry extends LocalVariableEntry { | ||
| 13 | |||
| 14 | protected final MethodDefEntry ownerEntry; | ||
| 15 | protected final TypeDescriptor desc; | ||
| 16 | |||
| 17 | public LocalVariableDefEntry(MethodDefEntry ownerEntry, int index, String name, TypeDescriptor desc) { | ||
| 18 | super(ownerEntry, index, name); | ||
| 19 | Preconditions.checkNotNull(desc, "Variable desc cannot be null"); | ||
| 20 | |||
| 21 | this.ownerEntry = ownerEntry; | ||
| 22 | this.desc = desc; | ||
| 23 | } | ||
| 24 | |||
| 25 | public LocalVariableDefEntry(MethodDefEntry ownerEntry, int index, String name) { | ||
| 26 | super(ownerEntry, index, name); | ||
| 27 | |||
| 28 | this.ownerEntry = ownerEntry; | ||
| 29 | |||
| 30 | int namedIndex = getNamedIndex(); | ||
| 31 | if (namedIndex < 0) { | ||
| 32 | this.desc = TypeDescriptor.of(ownerEntry.getOwnerClassEntry().getName()); | ||
| 33 | } else { | ||
| 34 | this.desc = ownerEntry.getDesc().getArgumentDescs().get(namedIndex); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public MethodDefEntry getOwnerEntry() { | ||
| 40 | return this.ownerEntry; | ||
| 41 | } | ||
| 42 | |||
| 43 | public TypeDescriptor getDesc() { | ||
| 44 | return desc; | ||
| 45 | } | ||
| 46 | |||
| 47 | public int getNamedIndex() { | ||
| 48 | // If we're not static, "this" is bound to index 0 | ||
| 49 | int indexOffset = ownerEntry.getAccess().isStatic() ? 0 : 1; | ||
| 50 | return index - indexOffset; | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public LocalVariableDefEntry updateOwnership(ClassEntry classEntry) { | ||
| 55 | return new LocalVariableDefEntry(ownerEntry.updateOwnership(classEntry), index, name, desc); | ||
| 56 | } | ||
| 57 | |||
| 58 | @Override | ||
| 59 | public int hashCode() { | ||
| 60 | return Utils.combineHashesOrdered(this.ownerEntry, this.desc.hashCode(), this.name.hashCode(), Integer.hashCode(this.index)); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | public boolean equals(Object other) { | ||
| 65 | return other instanceof LocalVariableDefEntry && equals((LocalVariableDefEntry) other); | ||
| 66 | } | ||
| 67 | |||
| 68 | public boolean equals(LocalVariableDefEntry other) { | ||
| 69 | return this.ownerEntry.equals(other.ownerEntry) && this.desc.equals(other.desc) && this.name.equals(other.name) && this.index == other.index; | ||
| 70 | } | ||
| 71 | |||
| 72 | @Override | ||
| 73 | public String toString() { | ||
| 74 | return this.ownerEntry + "(" + this.index + ":" + this.name + ":" + this.desc + ")"; | ||
| 75 | } | ||
| 76 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java new file mode 100644 index 0000000..a794d0a --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package cuchaz.enigma.mapping.entry; | ||
| 2 | |||
| 3 | import com.google.common.base.Preconditions; | ||
| 4 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 5 | import cuchaz.enigma.utils.Utils; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * TypeDescriptor... | ||
| 9 | * Created by Thog | ||
| 10 | * 19/10/2016 | ||
| 11 | */ | ||
| 12 | public class LocalVariableEntry implements Entry { | ||
| 13 | |||
| 14 | protected final MethodEntry ownerEntry; | ||
| 15 | protected final String name; | ||
| 16 | protected final int index; | ||
| 17 | |||
| 18 | public LocalVariableEntry(MethodEntry ownerEntry, int index, String name) { | ||
| 19 | Preconditions.checkNotNull(ownerEntry, "Variable owner cannot be null"); | ||
| 20 | Preconditions.checkNotNull(name, "Variable name cannot be null"); | ||
| 21 | Preconditions.checkArgument(index >= 0, "Index must be positive"); | ||
| 22 | |||
| 23 | this.ownerEntry = ownerEntry; | ||
| 24 | this.name = name; | ||
| 25 | this.index = index; | ||
| 26 | } | ||
| 27 | |||
| 28 | public MethodEntry getOwnerEntry() { | ||
| 29 | return this.ownerEntry; | ||
| 30 | } | ||
| 31 | |||
| 32 | public int getIndex() { | ||
| 33 | return index; | ||
| 34 | } | ||
| 35 | |||
| 36 | @Override | ||
| 37 | public String getName() { | ||
| 38 | return this.name; | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public ClassEntry getOwnerClassEntry() { | ||
| 43 | return this.ownerEntry.getOwnerClassEntry(); | ||
| 44 | } | ||
| 45 | |||
| 46 | @Override | ||
| 47 | public String getClassName() { | ||
| 48 | return this.ownerEntry.getClassName(); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public LocalVariableEntry updateOwnership(ClassEntry classEntry) { | ||
| 53 | return new LocalVariableEntry(ownerEntry.updateOwnership(classEntry), index, name); | ||
| 54 | } | ||
| 55 | |||
| 56 | public String getMethodName() { | ||
| 57 | return this.ownerEntry.getName(); | ||
| 58 | } | ||
| 59 | |||
| 60 | public MethodDescriptor getMethodDesc() { | ||
| 61 | return this.ownerEntry.getDesc(); | ||
| 62 | } | ||
| 63 | |||
| 64 | @Override | ||
| 65 | public int hashCode() { | ||
| 66 | return Utils.combineHashesOrdered(this.ownerEntry, this.name.hashCode(), Integer.hashCode(this.index)); | ||
| 67 | } | ||
| 68 | |||
| 69 | @Override | ||
| 70 | public boolean equals(Object other) { | ||
| 71 | return other instanceof LocalVariableEntry && equals((LocalVariableEntry) other); | ||
| 72 | } | ||
| 73 | |||
| 74 | public boolean equals(LocalVariableEntry other) { | ||
| 75 | return this.ownerEntry.equals(other.ownerEntry) && this.name.equals(other.name) && this.index == other.index; | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | public String toString() { | ||
| 80 | return this.ownerEntry + "(" + this.index + ":" + this.name + ")"; | ||
| 81 | } | ||
| 82 | } | ||
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 0000000..1d2c094 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java | |||
| @@ -0,0 +1,36 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 17 | |||
| 18 | public class MethodDefEntry extends MethodEntry { | ||
| 19 | |||
| 20 | private final AccessFlags access; | ||
| 21 | |||
| 22 | public MethodDefEntry(ClassEntry classEntry, String name, MethodDescriptor descriptor, AccessFlags access) { | ||
| 23 | super(classEntry, name, descriptor); | ||
| 24 | Preconditions.checkNotNull(access, "Method access cannot be null"); | ||
| 25 | this.access = access; | ||
| 26 | } | ||
| 27 | |||
| 28 | public AccessFlags getAccess() { | ||
| 29 | return access; | ||
| 30 | } | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public MethodDefEntry updateOwnership(ClassEntry classEntry) { | ||
| 34 | return new MethodDefEntry(new ClassEntry(classEntry.getName()), name, descriptor, access); | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java new file mode 100644 index 0000000..1abc5b1 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java | |||
| @@ -0,0 +1,80 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.google.common.base.Preconditions; | ||
| 15 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 16 | import cuchaz.enigma.utils.Utils; | ||
| 17 | |||
| 18 | public class MethodEntry implements Entry { | ||
| 19 | |||
| 20 | protected final ClassEntry classEntry; | ||
| 21 | protected final String name; | ||
| 22 | protected final MethodDescriptor descriptor; | ||
| 23 | |||
| 24 | public MethodEntry(ClassEntry classEntry, String name, MethodDescriptor descriptor) { | ||
| 25 | Preconditions.checkNotNull(classEntry, "Class cannot be null"); | ||
| 26 | Preconditions.checkNotNull(name, "Method name cannot be null"); | ||
| 27 | Preconditions.checkNotNull(descriptor, "Method descriptor cannot be null"); | ||
| 28 | |||
| 29 | this.classEntry = classEntry; | ||
| 30 | this.name = name; | ||
| 31 | this.descriptor = descriptor; | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public ClassEntry getOwnerClassEntry() { | ||
| 36 | return this.classEntry; | ||
| 37 | } | ||
| 38 | |||
| 39 | @Override | ||
| 40 | public String getName() { | ||
| 41 | return this.name; | ||
| 42 | } | ||
| 43 | |||
| 44 | public MethodDescriptor getDesc() { | ||
| 45 | return this.descriptor; | ||
| 46 | } | ||
| 47 | |||
| 48 | public boolean isConstructor() { | ||
| 49 | return name.equals("<init>") || name.equals("<clinit>"); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Override | ||
| 53 | public String getClassName() { | ||
| 54 | return this.classEntry.getName(); | ||
| 55 | } | ||
| 56 | |||
| 57 | @Override | ||
| 58 | public MethodEntry updateOwnership(ClassEntry classEntry) { | ||
| 59 | return new MethodEntry(new ClassEntry(classEntry.getName()), name, descriptor); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | public int hashCode() { | ||
| 64 | return Utils.combineHashesOrdered(this.classEntry, this.name, this.descriptor); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Override | ||
| 68 | public boolean equals(Object other) { | ||
| 69 | return other instanceof MethodEntry && equals((MethodEntry) other); | ||
| 70 | } | ||
| 71 | |||
| 72 | public boolean equals(MethodEntry other) { | ||
| 73 | return this.classEntry.equals(other.getOwnerClassEntry()) && this.name.equals(other.getName()) && this.descriptor.equals(other.getDesc()); | ||
| 74 | } | ||
| 75 | |||
| 76 | @Override | ||
| 77 | public String toString() { | ||
| 78 | return this.classEntry.getName() + "." + this.name + this.descriptor; | ||
| 79 | } | ||
| 80 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java b/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java new file mode 100644 index 0000000..e42a334 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java | |||
| @@ -0,0 +1,71 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import com.strobel.assembler.metadata.*; | ||
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 17 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 18 | |||
| 19 | import java.util.List; | ||
| 20 | |||
| 21 | public class ProcyonEntryFactory { | ||
| 22 | private final ReferencedEntryPool entryPool; | ||
| 23 | |||
| 24 | public ProcyonEntryFactory(ReferencedEntryPool entryPool) { | ||
| 25 | this.entryPool = entryPool; | ||
| 26 | } | ||
| 27 | |||
| 28 | private String getErasedSignature(MemberReference def) { | ||
| 29 | if (!(def instanceof MethodReference)) | ||
| 30 | return def.getErasedSignature(); | ||
| 31 | MethodReference methodReference = (MethodReference) def; | ||
| 32 | StringBuilder builder = new StringBuilder("("); | ||
| 33 | for (ParameterDefinition param : methodReference.getParameters()) { | ||
| 34 | TypeReference paramType = param.getParameterType(); | ||
| 35 | if (paramType.getErasedSignature().equals("Ljava/lang/Object;") && paramType.hasExtendsBound() && paramType.getExtendsBound() instanceof CompoundTypeReference) { | ||
| 36 | List<TypeReference> interfaces = ((CompoundTypeReference) paramType.getExtendsBound()).getInterfaces(); | ||
| 37 | interfaces.forEach((inter) -> builder.append(inter.getErasedSignature())); | ||
| 38 | } else | ||
| 39 | builder.append(paramType.getErasedSignature()); | ||
| 40 | } | ||
| 41 | builder.append(")"); | ||
| 42 | |||
| 43 | TypeReference returnType = methodReference.getReturnType(); | ||
| 44 | if (returnType.getErasedSignature().equals("Ljava/lang/Object;") && returnType.hasExtendsBound() && returnType.getExtendsBound() instanceof CompoundTypeReference) { | ||
| 45 | List<TypeReference> interfaces = ((CompoundTypeReference) returnType.getExtendsBound()).getInterfaces(); | ||
| 46 | interfaces.forEach((inter) -> builder.append(inter.getErasedSignature())); | ||
| 47 | } else | ||
| 48 | builder.append(returnType.getErasedSignature()); | ||
| 49 | return builder.toString(); | ||
| 50 | } | ||
| 51 | |||
| 52 | public FieldEntry getFieldEntry(MemberReference def) { | ||
| 53 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 54 | return entryPool.getField(classEntry, def.getName(), def.getErasedSignature()); | ||
| 55 | } | ||
| 56 | |||
| 57 | public FieldDefEntry getFieldDefEntry(FieldDefinition def) { | ||
| 58 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 59 | return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), new AccessFlags(def.getModifiers())); | ||
| 60 | } | ||
| 61 | |||
| 62 | public MethodEntry getMethodEntry(MemberReference def) { | ||
| 63 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 64 | return entryPool.getMethod(classEntry, def.getName(), getErasedSignature(def)); | ||
| 65 | } | ||
| 66 | |||
| 67 | public MethodDefEntry getMethodDefEntry(MethodDefinition def) { | ||
| 68 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 69 | return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), new AccessFlags(def.getModifiers())); | ||
| 70 | } | ||
| 71 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java b/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java new file mode 100644 index 0000000..338d209 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java | |||
| @@ -0,0 +1,53 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.mapping.entry; | ||
| 13 | |||
| 14 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 15 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 16 | |||
| 17 | import java.util.HashMap; | ||
| 18 | import java.util.Map; | ||
| 19 | |||
| 20 | public class ReferencedEntryPool { | ||
| 21 | private final Map<String, ClassEntry> classEntries = new HashMap<>(); | ||
| 22 | private final Map<String, Map<String, MethodEntry>> methodEntries = new HashMap<>(); | ||
| 23 | private final Map<String, Map<String, FieldEntry>> fieldEntries = new HashMap<>(); | ||
| 24 | |||
| 25 | public ClassEntry getClass(String name) { | ||
| 26 | return this.classEntries.computeIfAbsent(name, s -> new ClassEntry(name)); | ||
| 27 | } | ||
| 28 | |||
| 29 | public MethodEntry getMethod(ClassEntry ownerEntry, String name, String desc) { | ||
| 30 | return getMethod(ownerEntry, name, new MethodDescriptor(desc)); | ||
| 31 | } | ||
| 32 | |||
| 33 | public MethodEntry getMethod(ClassEntry ownerEntry, String name, MethodDescriptor desc) { | ||
| 34 | String key = name + desc.toString(); | ||
| 35 | return getClassMethods(ownerEntry.getName()).computeIfAbsent(key, s -> new MethodEntry(ownerEntry, name, desc)); | ||
| 36 | } | ||
| 37 | |||
| 38 | public FieldEntry getField(ClassEntry ownerEntry, String name, String desc) { | ||
| 39 | return getField(ownerEntry, name, new TypeDescriptor(desc)); | ||
| 40 | } | ||
| 41 | |||
| 42 | public FieldEntry getField(ClassEntry ownerEntry, String name, TypeDescriptor desc) { | ||
| 43 | return getClassFields(ownerEntry.getName()).computeIfAbsent(name, s -> new FieldEntry(ownerEntry, name, desc)); | ||
| 44 | } | ||
| 45 | |||
| 46 | private Map<String, MethodEntry> getClassMethods(String name) { | ||
| 47 | return methodEntries.computeIfAbsent(name, s -> new HashMap<>()); | ||
| 48 | } | ||
| 49 | |||
| 50 | private Map<String, FieldEntry> getClassFields(String name) { | ||
| 51 | return fieldEntries.computeIfAbsent(name, s -> new HashMap<>()); | ||
| 52 | } | ||
| 53 | } | ||