diff options
| author | 2016-07-04 18:14:22 +1000 | |
|---|---|---|
| committer | 2016-07-04 18:14:22 +1000 | |
| commit | 59e189bef2b5e6d129fb7c2c988ed0b2130e36ac (patch) | |
| tree | 2b638e60905251de85a4917152d6fc39a4112194 /src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |
| parent | Fixed Obf Class list order (diff) | |
| download | enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.gz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.xz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.zip | |
Reformat
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MethodMapping.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MethodMapping.java | 93 |
1 files changed, 31 insertions, 62 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index fbd97bd..6e7c1ef 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -12,18 +12,16 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.Map; | 15 | import java.util.Map; |
| 17 | import java.util.Map.Entry; | ||
| 18 | 16 | ||
| 19 | public class MethodMapping implements Serializable, Comparable<MethodMapping>, MemberMapping<BehaviorEntry> { | 17 | import cuchaz.enigma.throwables.MappingConflict; |
| 20 | 18 | ||
| 21 | private static final long serialVersionUID = -4409570216084263978L; | 19 | public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<BehaviorEntry> { |
| 22 | 20 | ||
| 23 | private String m_obfName; | 21 | private String obfName; |
| 24 | private String m_deobfName; | 22 | private String deobfName; |
| 25 | private Signature m_obfSignature; | 23 | private Signature obfSignature; |
| 26 | private Map<Integer, ArgumentMapping> m_arguments; | 24 | private Map<Integer, ArgumentMapping> arguments; |
| 27 | 25 | ||
| 28 | public MethodMapping(String obfName, Signature obfSignature) { | 26 | public MethodMapping(String obfName, Signature obfSignature) { |
| 29 | this(obfName, obfSignature, null); | 27 | this(obfName, obfSignature, null); |
| @@ -36,62 +34,42 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 36 | if (obfSignature == null) { | 34 | if (obfSignature == null) { |
| 37 | throw new IllegalArgumentException("obf signature cannot be null!"); | 35 | throw new IllegalArgumentException("obf signature cannot be null!"); |
| 38 | } | 36 | } |
| 39 | this.m_obfName = obfName; | 37 | this.obfName = obfName; |
| 40 | this.m_deobfName = NameValidator.validateMethodName(deobfName); | 38 | this.deobfName = NameValidator.validateMethodName(deobfName); |
| 41 | this.m_obfSignature = obfSignature; | 39 | this.obfSignature = obfSignature; |
| 42 | this.m_arguments = Maps.newTreeMap(); | 40 | this.arguments = Maps.newTreeMap(); |
| 43 | } | ||
| 44 | |||
| 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { | ||
| 46 | this.m_obfName = other.m_obfName; | ||
| 47 | this.m_deobfName = other.m_deobfName; | ||
| 48 | this.m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); | ||
| 49 | this.m_arguments = Maps.newTreeMap(); | ||
| 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { | ||
| 51 | this.m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); | ||
| 52 | } | ||
| 53 | } | 41 | } |
| 54 | 42 | ||
| 55 | @Override | 43 | @Override |
| 56 | public String getObfName() { | 44 | public String getObfName() { |
| 57 | return this.m_obfName; | 45 | return this.obfName; |
| 58 | } | ||
| 59 | |||
| 60 | public void setObfName(String val) { | ||
| 61 | this.m_obfName = NameValidator.validateMethodName(val); | ||
| 62 | } | 46 | } |
| 63 | 47 | ||
| 64 | public String getDeobfName() { | 48 | public String getDeobfName() { |
| 65 | return this.m_deobfName; | 49 | return this.deobfName; |
| 66 | } | 50 | } |
| 67 | 51 | ||
| 68 | public void setDeobfName(String val) { | 52 | public void setDeobfName(String val) { |
| 69 | this.m_deobfName = NameValidator.validateMethodName(val); | 53 | this.deobfName = NameValidator.validateMethodName(val); |
| 70 | } | 54 | } |
| 71 | 55 | ||
| 72 | public Signature getObfSignature() { | 56 | public Signature getObfSignature() { |
| 73 | return this.m_obfSignature; | 57 | return this.obfSignature; |
| 74 | } | ||
| 75 | |||
| 76 | public void setObfSignature(Signature val) { | ||
| 77 | this.m_obfSignature = val; | ||
| 78 | } | 58 | } |
| 79 | 59 | ||
| 80 | public Iterable<ArgumentMapping> arguments() { | 60 | public Iterable<ArgumentMapping> arguments() { |
| 81 | return this.m_arguments.values(); | 61 | return this.arguments.values(); |
| 82 | } | 62 | } |
| 83 | 63 | ||
| 84 | public boolean isConstructor() { | 64 | public void addArgumentMapping(ArgumentMapping argumentMapping) throws MappingConflict { |
| 85 | return this.m_obfName.startsWith("<"); | 65 | if (this.arguments.containsKey(argumentMapping.getIndex())) { |
| 86 | } | 66 | throw new MappingConflict("argument", argumentMapping.getName(), this.arguments.get(argumentMapping.getIndex()).getName()); |
| 87 | 67 | } | |
| 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { | 68 | this.arguments.put(argumentMapping.getIndex(), argumentMapping); |
| 89 | boolean wasAdded = this.m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; | ||
| 90 | assert (wasAdded); | ||
| 91 | } | 69 | } |
| 92 | 70 | ||
| 93 | public String getObfArgumentName(int index) { | 71 | public String getObfArgumentName(int index) { |
| 94 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 72 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 95 | if (argumentMapping != null) { | 73 | if (argumentMapping != null) { |
| 96 | return argumentMapping.getName(); | 74 | return argumentMapping.getName(); |
| 97 | } | 75 | } |
| @@ -100,7 +78,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 100 | } | 78 | } |
| 101 | 79 | ||
| 102 | public String getDeobfArgumentName(int index) { | 80 | public String getDeobfArgumentName(int index) { |
| 103 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 81 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 104 | if (argumentMapping != null) { | 82 | if (argumentMapping != null) { |
| 105 | return argumentMapping.getName(); | 83 | return argumentMapping.getName(); |
| 106 | } | 84 | } |
| @@ -109,10 +87,10 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 109 | } | 87 | } |
| 110 | 88 | ||
| 111 | public void setArgumentName(int index, String name) { | 89 | public void setArgumentName(int index, String name) { |
| 112 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 90 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 113 | if (argumentMapping == null) { | 91 | if (argumentMapping == null) { |
| 114 | argumentMapping = new ArgumentMapping(index, name); | 92 | argumentMapping = new ArgumentMapping(index, name); |
| 115 | boolean wasAdded = this.m_arguments.put(index, argumentMapping) == null; | 93 | boolean wasAdded = this.arguments.put(index, argumentMapping) == null; |
| 116 | assert (wasAdded); | 94 | assert (wasAdded); |
| 117 | } else { | 95 | } else { |
| 118 | argumentMapping.setName(name); | 96 | argumentMapping.setName(name); |
| @@ -120,7 +98,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 120 | } | 98 | } |
| 121 | 99 | ||
| 122 | public void removeArgumentName(int index) { | 100 | public void removeArgumentName(int index) { |
| 123 | boolean wasRemoved = this.m_arguments.remove(index) != null; | 101 | boolean wasRemoved = this.arguments.remove(index) != null; |
| 124 | assert (wasRemoved); | 102 | assert (wasRemoved); |
| 125 | } | 103 | } |
| 126 | 104 | ||
| @@ -128,15 +106,15 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 128 | public String toString() { | 106 | public String toString() { |
| 129 | StringBuilder buf = new StringBuilder(); | 107 | StringBuilder buf = new StringBuilder(); |
| 130 | buf.append("\t"); | 108 | buf.append("\t"); |
| 131 | buf.append(m_obfName); | 109 | buf.append(this.obfName); |
| 132 | buf.append(" <-> "); | 110 | buf.append(" <-> "); |
| 133 | buf.append(m_deobfName); | 111 | buf.append(this.deobfName); |
| 134 | buf.append("\n"); | 112 | buf.append("\n"); |
| 135 | buf.append("\t"); | 113 | buf.append("\t"); |
| 136 | buf.append(m_obfSignature); | 114 | buf.append(this.obfSignature); |
| 137 | buf.append("\n"); | 115 | buf.append("\n"); |
| 138 | buf.append("\tArguments:\n"); | 116 | buf.append("\tArguments:\n"); |
| 139 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { | 117 | for (ArgumentMapping argumentMapping : this.arguments.values()) { |
| 140 | buf.append("\t\t"); | 118 | buf.append("\t\t"); |
| 141 | buf.append(argumentMapping.getIndex()); | 119 | buf.append(argumentMapping.getIndex()); |
| 142 | buf.append(" -> "); | 120 | buf.append(" -> "); |
| @@ -148,24 +126,15 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 148 | 126 | ||
| 149 | @Override | 127 | @Override |
| 150 | public int compareTo(MethodMapping other) { | 128 | public int compareTo(MethodMapping other) { |
| 151 | return (this.m_obfName + this.m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); | 129 | return (this.obfName + this.obfSignature).compareTo(other.obfName + other.obfSignature); |
| 152 | } | 130 | } |
| 153 | 131 | ||
| 154 | public boolean containsArgument(String name) { | 132 | public boolean containsArgument(String name) { |
| 155 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { | 133 | for (ArgumentMapping argumentMapping : this.arguments.values()) { |
| 156 | if (argumentMapping.getName().equals(name)) { | 134 | if (argumentMapping.getName().equals(name)) { |
| 157 | return true; | 135 | return true; |
| 158 | } | 136 | } |
| 159 | } | 137 | } |
| 160 | return false; | 138 | return false; |
| 161 | } | 139 | } |
| 162 | |||
| 163 | @Override | ||
| 164 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { | ||
| 165 | if (isConstructor()) { | ||
| 166 | return new ConstructorEntry(classEntry, this.m_obfSignature); | ||
| 167 | } else { | ||
| 168 | return new MethodEntry(classEntry, this.m_obfName, this.m_obfSignature); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | 140 | } |