diff options
| author | 2019-01-24 14:48:32 +0200 | |
|---|---|---|
| committer | 2019-01-24 13:48:32 +0100 | |
| commit | 00fcd0550fcdda621c2e4662f6ddd55ce673b931 (patch) | |
| tree | 6f9e4c24dbcc6d118fceec56adf7bf9d747a485c /src/main/java/cuchaz/enigma/mapping/entry | |
| parent | mark as 0.13.0-SNAPSHOT for preliminary development (diff) | |
| download | enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.gz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.xz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.zip | |
[WIP] Mapping rework (#91)
* Move packages
* Mapping & entry refactor: first pass
* Fix deobf -> obf tree remapping
* Resolve various issues
* Give all entries the potential for parents and treat inner classes as children
* Deobf UI tree elements
* Tests pass
* Sort mapping output
* Fix delta tracking
* Index separation and first pass for #97
* Keep track of remapped jar index
* Fix child entries not being remapped
* Drop non-root entries
* Track dropped mappings
* Fix enigma mapping ordering
* EntryTreeNode interface
* Small tweaks
* Naive full index remap on rename
* Entries can resolve to more than one root entry
* Support alternative resolution strategies
* Bridge method resolution
* Tests pass
* Fix mappings being used where there are none
* Fix methods with different descriptors being considered unique. closes #89
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/entry')
13 files changed, 0 insertions, 814 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java deleted file mode 100644 index df72e7e..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java +++ /dev/null | |||
| @@ -1,38 +0,0 @@ | |||
| 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.Signature; | ||
| 17 | |||
| 18 | public class ClassDefEntry extends ClassEntry implements DefEntry { | ||
| 19 | private final AccessFlags access; | ||
| 20 | private final Signature signature; | ||
| 21 | |||
| 22 | public ClassDefEntry(String className, Signature signature, AccessFlags access) { | ||
| 23 | super(className); | ||
| 24 | Preconditions.checkNotNull(signature, "Class signature cannot be null"); | ||
| 25 | Preconditions.checkNotNull(access, "Class access cannot be null"); | ||
| 26 | this.signature = signature; | ||
| 27 | this.access = access; | ||
| 28 | } | ||
| 29 | |||
| 30 | public Signature getSignature() { | ||
| 31 | return signature; | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public AccessFlags getAccess() { | ||
| 36 | return access; | ||
| 37 | } | ||
| 38 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java deleted file mode 100644 index c795825..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/ClassEntry.java +++ /dev/null | |||
| @@ -1,175 +0,0 @@ | |||
| 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 isArray() { | ||
| 81 | return this.name.lastIndexOf('[') >= 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | public boolean isInnerClass() { | ||
| 85 | return this.name.lastIndexOf('$') >= 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | public List<String> getClassChainNames() { | ||
| 89 | return Lists.newArrayList(this.name.split("\\$")); | ||
| 90 | } | ||
| 91 | |||
| 92 | public List<ClassEntry> getClassChain() { | ||
| 93 | List<ClassEntry> entries = Lists.newArrayList(); | ||
| 94 | StringBuilder buf = new StringBuilder(); | ||
| 95 | for (String name : getClassChainNames()) { | ||
| 96 | if (buf.length() > 0) { | ||
| 97 | buf.append("$"); | ||
| 98 | } | ||
| 99 | buf.append(name); | ||
| 100 | entries.add(new ClassEntry(buf.toString())); | ||
| 101 | } | ||
| 102 | return entries; | ||
| 103 | } | ||
| 104 | |||
| 105 | public String getOutermostClassName() { | ||
| 106 | if (isInnerClass()) { | ||
| 107 | return this.name.substring(0, this.name.indexOf('$')); | ||
| 108 | } | ||
| 109 | return this.name; | ||
| 110 | } | ||
| 111 | |||
| 112 | public ClassEntry getOutermostClassEntry() { | ||
| 113 | return new ClassEntry(getOutermostClassName()); | ||
| 114 | } | ||
| 115 | |||
| 116 | public String getOuterClassName() { | ||
| 117 | if (!isInnerClass()) { | ||
| 118 | throw new Error("This is not an inner class!"); | ||
| 119 | } | ||
| 120 | return this.name.substring(0, this.name.lastIndexOf('$')); | ||
| 121 | } | ||
| 122 | |||
| 123 | public ClassEntry getOuterClassEntry() { | ||
| 124 | return new ClassEntry(getOuterClassName()); | ||
| 125 | } | ||
| 126 | |||
| 127 | public String getInnermostClassName() { | ||
| 128 | if (!isInnerClass()) { | ||
| 129 | throw new Error("This is not an inner class!"); | ||
| 130 | } | ||
| 131 | return this.name.substring(this.name.lastIndexOf('$') + 1); | ||
| 132 | } | ||
| 133 | |||
| 134 | public boolean isInDefaultPackage() { | ||
| 135 | return this.name.indexOf('/') < 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | public String getPackageName() { | ||
| 139 | return getPackageName(this.name); | ||
| 140 | } | ||
| 141 | |||
| 142 | public String getSimpleName() { | ||
| 143 | int pos = this.name.lastIndexOf('/'); | ||
| 144 | if (pos > 0) { | ||
| 145 | return this.name.substring(pos + 1); | ||
| 146 | } | ||
| 147 | return this.name; | ||
| 148 | } | ||
| 149 | |||
| 150 | public static String getPackageName(String name) { | ||
| 151 | int pos = name.lastIndexOf('/'); | ||
| 152 | if (pos > 0) { | ||
| 153 | return name.substring(0, pos); | ||
| 154 | } | ||
| 155 | return null; | ||
| 156 | } | ||
| 157 | |||
| 158 | public ClassEntry buildClassEntry(List<ClassEntry> classChain) { | ||
| 159 | assert (classChain.contains(this)); | ||
| 160 | StringBuilder buf = new StringBuilder(); | ||
| 161 | for (ClassEntry chainEntry : classChain) { | ||
| 162 | if (buf.length() == 0) { | ||
| 163 | buf.append(chainEntry.getName()); | ||
| 164 | } else { | ||
| 165 | buf.append("$"); | ||
| 166 | buf.append(chainEntry.isInnerClass() ? chainEntry.getInnermostClassName() : chainEntry.getSimpleName()); | ||
| 167 | } | ||
| 168 | |||
| 169 | if (chainEntry == this) { | ||
| 170 | break; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | return new ClassEntry(buf.toString()); | ||
| 174 | } | ||
| 175 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/DefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/DefEntry.java deleted file mode 100644 index 43ad027..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/DefEntry.java +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | package cuchaz.enigma.mapping.entry; | ||
| 2 | |||
| 3 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 4 | |||
| 5 | public interface DefEntry extends Entry { | ||
| 6 | AccessFlags getAccess(); | ||
| 7 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/Entry.java b/src/main/java/cuchaz/enigma/mapping/entry/Entry.java deleted file mode 100644 index b612140..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/Entry.java +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 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 deleted file mode 100644 index 5bd159f..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/EntryFactory.java +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 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 deleted file mode 100644 index 223410f..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 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.Signature; | ||
| 17 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 18 | |||
| 19 | public class FieldDefEntry extends FieldEntry implements DefEntry { | ||
| 20 | private final AccessFlags access; | ||
| 21 | private final Signature signature; | ||
| 22 | |||
| 23 | public FieldDefEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc, Signature signature, AccessFlags access) { | ||
| 24 | super(ownerEntry, name, desc); | ||
| 25 | Preconditions.checkNotNull(access, "Field access cannot be null"); | ||
| 26 | Preconditions.checkNotNull(signature, "Field signature cannot be null"); | ||
| 27 | this.access = access; | ||
| 28 | this.signature = signature; | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | public AccessFlags getAccess() { | ||
| 33 | return access; | ||
| 34 | } | ||
| 35 | |||
| 36 | public Signature getSignature() { | ||
| 37 | return signature; | ||
| 38 | } | ||
| 39 | |||
| 40 | @Override | ||
| 41 | public FieldDefEntry updateOwnership(ClassEntry owner) { | ||
| 42 | return new FieldDefEntry(owner, this.name, this.desc, signature, access); | ||
| 43 | } | ||
| 44 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java deleted file mode 100644 index b6e1554..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/FieldEntry.java +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 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 deleted file mode 100644 index d186664..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableDefEntry.java +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 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 | this(ownerEntry, index, name, true, desc); | ||
| 19 | } | ||
| 20 | |||
| 21 | public LocalVariableDefEntry(MethodDefEntry ownerEntry, int index, String name, boolean parameter, TypeDescriptor desc) { | ||
| 22 | super(ownerEntry, index, name, parameter); | ||
| 23 | Preconditions.checkNotNull(desc, "Variable desc cannot be null"); | ||
| 24 | |||
| 25 | this.ownerEntry = ownerEntry; | ||
| 26 | this.desc = desc; | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public MethodDefEntry getOwnerEntry() { | ||
| 31 | return this.ownerEntry; | ||
| 32 | } | ||
| 33 | |||
| 34 | public TypeDescriptor getDesc() { | ||
| 35 | return desc; | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public LocalVariableDefEntry updateOwnership(ClassEntry classEntry) { | ||
| 40 | return new LocalVariableDefEntry(ownerEntry.updateOwnership(classEntry), index, name, parameter, desc); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Override | ||
| 44 | public int hashCode() { | ||
| 45 | return Utils.combineHashesOrdered(this.ownerEntry, this.desc.hashCode(), this.name.hashCode(), Integer.hashCode(this.index)); | ||
| 46 | } | ||
| 47 | |||
| 48 | @Override | ||
| 49 | public boolean equals(Object other) { | ||
| 50 | return other instanceof LocalVariableDefEntry && equals((LocalVariableDefEntry) other); | ||
| 51 | } | ||
| 52 | |||
| 53 | public boolean equals(LocalVariableDefEntry other) { | ||
| 54 | return this.ownerEntry.equals(other.ownerEntry) && this.desc.equals(other.desc) && this.name.equals(other.name) && this.index == other.index; | ||
| 55 | } | ||
| 56 | |||
| 57 | @Override | ||
| 58 | public String toString() { | ||
| 59 | return this.ownerEntry + "(" + this.index + ":" + this.name + ":" + this.desc + ")"; | ||
| 60 | } | ||
| 61 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java deleted file mode 100644 index 3507b25..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/LocalVariableEntry.java +++ /dev/null | |||
| @@ -1,93 +0,0 @@ | |||
| 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 | protected final boolean parameter; | ||
| 18 | |||
| 19 | @Deprecated | ||
| 20 | public LocalVariableEntry(MethodEntry ownerEntry, int index, String name) { | ||
| 21 | this(ownerEntry, index, name, true); | ||
| 22 | } | ||
| 23 | |||
| 24 | public LocalVariableEntry(MethodEntry ownerEntry, int index, String name, boolean parameter) { | ||
| 25 | Preconditions.checkNotNull(ownerEntry, "Variable owner cannot be null"); | ||
| 26 | Preconditions.checkNotNull(name, "Variable name cannot be null"); | ||
| 27 | Preconditions.checkArgument(index >= 0, "Index must be positive"); | ||
| 28 | |||
| 29 | this.ownerEntry = ownerEntry; | ||
| 30 | this.name = name; | ||
| 31 | this.index = index; | ||
| 32 | this.parameter = parameter; | ||
| 33 | } | ||
| 34 | |||
| 35 | public boolean isParameter() { | ||
| 36 | return this.parameter; | ||
| 37 | } | ||
| 38 | |||
| 39 | public MethodEntry getOwnerEntry() { | ||
| 40 | return this.ownerEntry; | ||
| 41 | } | ||
| 42 | |||
| 43 | public int getIndex() { | ||
| 44 | return index; | ||
| 45 | } | ||
| 46 | |||
| 47 | @Override | ||
| 48 | public String getName() { | ||
| 49 | return this.name; | ||
| 50 | } | ||
| 51 | |||
| 52 | @Override | ||
| 53 | public ClassEntry getOwnerClassEntry() { | ||
| 54 | return this.ownerEntry.getOwnerClassEntry(); | ||
| 55 | } | ||
| 56 | |||
| 57 | @Override | ||
| 58 | public String getClassName() { | ||
| 59 | return this.ownerEntry.getClassName(); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | public LocalVariableEntry updateOwnership(ClassEntry classEntry) { | ||
| 64 | return new LocalVariableEntry(ownerEntry.updateOwnership(classEntry), index, name, parameter); | ||
| 65 | } | ||
| 66 | |||
| 67 | public String getMethodName() { | ||
| 68 | return this.ownerEntry.getName(); | ||
| 69 | } | ||
| 70 | |||
| 71 | public MethodDescriptor getMethodDesc() { | ||
| 72 | return this.ownerEntry.getDesc(); | ||
| 73 | } | ||
| 74 | |||
| 75 | @Override | ||
| 76 | public int hashCode() { | ||
| 77 | return Utils.combineHashesOrdered(this.ownerEntry, this.name.hashCode(), Integer.hashCode(this.index)); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Override | ||
| 81 | public boolean equals(Object other) { | ||
| 82 | return other instanceof LocalVariableEntry && equals((LocalVariableEntry) other); | ||
| 83 | } | ||
| 84 | |||
| 85 | public boolean equals(LocalVariableEntry other) { | ||
| 86 | return this.ownerEntry.equals(other.ownerEntry) && this.name.equals(other.name) && this.index == other.index; | ||
| 87 | } | ||
| 88 | |||
| 89 | @Override | ||
| 90 | public String toString() { | ||
| 91 | return this.ownerEntry + "(" + this.index + ":" + this.name + ")"; | ||
| 92 | } | ||
| 93 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java deleted file mode 100644 index fa9e668..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 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 | import cuchaz.enigma.mapping.Signature; | ||
| 18 | |||
| 19 | public class MethodDefEntry extends MethodEntry implements DefEntry { | ||
| 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 | @Override | ||
| 33 | public AccessFlags getAccess() { | ||
| 34 | return access; | ||
| 35 | } | ||
| 36 | |||
| 37 | public Signature getSignature() { | ||
| 38 | return signature; | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public MethodDefEntry updateOwnership(ClassEntry classEntry) { | ||
| 43 | return new MethodDefEntry(new ClassEntry(classEntry.getName()), name, descriptor, signature, access); | ||
| 44 | } | ||
| 45 | |||
| 46 | public int getArgumentIndex(ClassDefEntry ownerEntry, int localVariableIndex) { | ||
| 47 | int argumentIndex = localVariableIndex; | ||
| 48 | |||
| 49 | // Enum constructors have an implicit "name" and "ordinal" parameter as well as "this" | ||
| 50 | if (ownerEntry.getAccess().isEnum() && getName().startsWith("<")) { | ||
| 51 | argumentIndex -= 2; | ||
| 52 | } | ||
| 53 | |||
| 54 | // If we're not static, "this" is bound to index 0 | ||
| 55 | if (!getAccess().isStatic()) { | ||
| 56 | argumentIndex -= 1; | ||
| 57 | } | ||
| 58 | |||
| 59 | return argumentIndex; | ||
| 60 | } | ||
| 61 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java deleted file mode 100644 index 1abc5b1..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/MethodEntry.java +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 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 deleted file mode 100644 index 73770c5..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 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.FieldDefinition; | ||
| 15 | import com.strobel.assembler.metadata.MemberReference; | ||
| 16 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 17 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 18 | import cuchaz.enigma.mapping.MethodDescriptor; | ||
| 19 | import cuchaz.enigma.mapping.Signature; | ||
| 20 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 21 | |||
| 22 | public class ProcyonEntryFactory { | ||
| 23 | private final ReferencedEntryPool entryPool; | ||
| 24 | |||
| 25 | public ProcyonEntryFactory(ReferencedEntryPool entryPool) { | ||
| 26 | this.entryPool = entryPool; | ||
| 27 | } | ||
| 28 | |||
| 29 | public FieldEntry getFieldEntry(MemberReference def) { | ||
| 30 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 31 | return entryPool.getField(classEntry, def.getName(), def.getErasedSignature()); | ||
| 32 | } | ||
| 33 | |||
| 34 | public FieldDefEntry getFieldDefEntry(FieldDefinition def) { | ||
| 35 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 36 | return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers())); | ||
| 37 | } | ||
| 38 | |||
| 39 | public MethodEntry getMethodEntry(MemberReference def) { | ||
| 40 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 41 | return entryPool.getMethod(classEntry, def.getName(), def.getErasedSignature()); | ||
| 42 | } | ||
| 43 | |||
| 44 | public MethodDefEntry getMethodDefEntry(MethodDefinition def) { | ||
| 45 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | ||
| 46 | return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers())); | ||
| 47 | } | ||
| 48 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java b/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java deleted file mode 100644 index 12b3955..0000000 --- a/src/main/java/cuchaz/enigma/mapping/entry/ReferencedEntryPool.java +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 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 | // TODO: FIXME - I'm a hack! | ||
| 27 | if ("[T".equals(name) || "[[T".equals(name) || "[[[T".equals(name)) { | ||
| 28 | name = name.replaceAll("T", "Ljava/lang/Object;"); | ||
| 29 | } | ||
| 30 | |||
| 31 | final String computeName = name; | ||
| 32 | return this.classEntries.computeIfAbsent(name, s -> new ClassEntry(computeName)); | ||
| 33 | } | ||
| 34 | |||
| 35 | public MethodEntry getMethod(ClassEntry ownerEntry, String name, String desc) { | ||
| 36 | return getMethod(ownerEntry, name, new MethodDescriptor(desc)); | ||
| 37 | } | ||
| 38 | |||
| 39 | public MethodEntry getMethod(ClassEntry ownerEntry, String name, MethodDescriptor desc) { | ||
| 40 | String key = name + desc.toString(); | ||
| 41 | return getClassMethods(ownerEntry.getName()).computeIfAbsent(key, s -> new MethodEntry(ownerEntry, name, desc)); | ||
| 42 | } | ||
| 43 | |||
| 44 | public FieldEntry getField(ClassEntry ownerEntry, String name, String desc) { | ||
| 45 | return getField(ownerEntry, name, new TypeDescriptor(desc)); | ||
| 46 | } | ||
| 47 | |||
| 48 | public FieldEntry getField(ClassEntry ownerEntry, String name, TypeDescriptor desc) { | ||
| 49 | return getClassFields(ownerEntry.getName()).computeIfAbsent(name, s -> new FieldEntry(ownerEntry, name, desc)); | ||
| 50 | } | ||
| 51 | |||
| 52 | private Map<String, MethodEntry> getClassMethods(String name) { | ||
| 53 | return methodEntries.computeIfAbsent(name, s -> new HashMap<>()); | ||
| 54 | } | ||
| 55 | |||
| 56 | private Map<String, FieldEntry> getClassFields(String name) { | ||
| 57 | return fieldEntries.computeIfAbsent(name, s -> new HashMap<>()); | ||
| 58 | } | ||
| 59 | } | ||