diff options
| author | 2017-03-08 08:17:04 +0100 | |
|---|---|---|
| committer | 2017-03-08 08:17:04 +0100 | |
| commit | 6e464ea251cab63c776ece0b2a356f1498ffa294 (patch) | |
| tree | 5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java | |
| parent | Drop unix case style and implement hashCode when equals is overrided (diff) | |
| download | enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip | |
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java index 9864333..ddc5af4 100644 --- a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java +++ b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | |||
| 11 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 12 | 13 | ||
| 13 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| @@ -18,74 +19,74 @@ import java.util.List; | |||
| 18 | 19 | ||
| 19 | public class SignatureUpdater { | 20 | public class SignatureUpdater { |
| 20 | 21 | ||
| 21 | public interface ClassNameUpdater { | 22 | public static String update(String signature, ClassNameUpdater updater) { |
| 22 | String update(String className); | 23 | try { |
| 23 | } | 24 | StringBuilder buf = new StringBuilder(); |
| 24 | 25 | ||
| 25 | public static String update(String signature, ClassNameUpdater updater) { | 26 | // read the signature character-by-character |
| 26 | try { | 27 | StringReader reader = new StringReader(signature); |
| 27 | StringBuilder buf = new StringBuilder(); | 28 | int i; |
| 29 | while ((i = reader.read()) != -1) { | ||
| 30 | char c = (char) i; | ||
| 28 | 31 | ||
| 29 | // read the signature character-by-character | 32 | // does this character start a class name? |
| 30 | StringReader reader = new StringReader(signature); | 33 | if (c == 'L') { |
| 31 | int i; | 34 | // update the class name and add it to the buffer |
| 32 | while ((i = reader.read()) != -1) { | 35 | buf.append('L'); |
| 33 | char c = (char) i; | 36 | String className = readClass(reader); |
| 37 | if (className == null) { | ||
| 38 | throw new IllegalArgumentException("Malformed signature: " + signature); | ||
| 39 | } | ||
| 40 | buf.append(updater.update(className)); | ||
| 41 | buf.append(';'); | ||
| 42 | } else { | ||
| 43 | // copy the character into the buffer | ||
| 44 | buf.append(c); | ||
| 45 | } | ||
| 46 | } | ||
| 34 | 47 | ||
| 35 | // does this character start a class name? | 48 | return buf.toString(); |
| 36 | if (c == 'L') { | 49 | } catch (IOException ex) { |
| 37 | // update the class name and add it to the buffer | 50 | // I'm pretty sure a StringReader will never throw one of these |
| 38 | buf.append('L'); | 51 | throw new Error(ex); |
| 39 | String className = readClass(reader); | 52 | } |
| 40 | if (className == null) { | 53 | } |
| 41 | throw new IllegalArgumentException("Malformed signature: " + signature); | ||
| 42 | } | ||
| 43 | buf.append(updater.update(className)); | ||
| 44 | buf.append(';'); | ||
| 45 | } else { | ||
| 46 | // copy the character into the buffer | ||
| 47 | buf.append(c); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | 54 | ||
| 51 | return buf.toString(); | 55 | private static String readClass(StringReader reader) throws IOException { |
| 52 | } catch (IOException ex) { | 56 | // read all the characters in the buffer until we hit a ';' |
| 53 | // I'm pretty sure a StringReader will never throw one of these | 57 | // remember to treat generics correctly |
| 54 | throw new Error(ex); | 58 | StringBuilder buf = new StringBuilder(); |
| 55 | } | 59 | int depth = 0; |
| 56 | } | 60 | int i; |
| 61 | while ((i = reader.read()) != -1) { | ||
| 62 | char c = (char) i; | ||
| 57 | 63 | ||
| 58 | private static String readClass(StringReader reader) throws IOException { | 64 | if (c == '<') { |
| 59 | // read all the characters in the buffer until we hit a ';' | 65 | depth++; |
| 60 | // remember to treat generics correctly | 66 | } else if (c == '>') { |
| 61 | StringBuilder buf = new StringBuilder(); | 67 | depth--; |
| 62 | int depth = 0; | 68 | } else if (depth == 0) { |
| 63 | int i; | 69 | if (c == ';') { |
| 64 | while ((i = reader.read()) != -1) { | 70 | return buf.toString(); |
| 65 | char c = (char) i; | 71 | } else { |
| 72 | buf.append(c); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 66 | 76 | ||
| 67 | if (c == '<') { | 77 | return null; |
| 68 | depth++; | 78 | } |
| 69 | } else if (c == '>') { | ||
| 70 | depth--; | ||
| 71 | } else if (depth == 0) { | ||
| 72 | if (c == ';') { | ||
| 73 | return buf.toString(); | ||
| 74 | } else { | ||
| 75 | buf.append(c); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | 79 | ||
| 80 | return null; | 80 | public static List<String> getClasses(String signature) { |
| 81 | } | 81 | final List<String> classNames = Lists.newArrayList(); |
| 82 | update(signature, className -> { | ||
| 83 | classNames.add(className); | ||
| 84 | return className; | ||
| 85 | }); | ||
| 86 | return classNames; | ||
| 87 | } | ||
| 82 | 88 | ||
| 83 | public static List<String> getClasses(String signature) { | 89 | public interface ClassNameUpdater { |
| 84 | final List<String> classNames = Lists.newArrayList(); | 90 | String update(String className); |
| 85 | update(signature, className -> { | 91 | } |
| 86 | classNames.add(className); | ||
| 87 | return className; | ||
| 88 | }); | ||
| 89 | return classNames; | ||
| 90 | } | ||
| 91 | } | 92 | } |