diff options
| author | 2015-01-13 23:25:04 -0500 | |
|---|---|---|
| committer | 2015-01-13 23:25:04 -0500 | |
| commit | 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f (patch) | |
| tree | bdd8a2c52c2fe053ba3460614bde8542e5378dbe /src/cuchaz/enigma/mapping/SignatureUpdater.java | |
| parent | got rid of gradle in favor of ivy+ssjb (diff) | |
| download | enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.gz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.xz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.zip | |
source format change
don't hate me too much if you were planning a big merge. =P
Diffstat (limited to 'src/cuchaz/enigma/mapping/SignatureUpdater.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/SignatureUpdater.java | 88 |
1 files changed, 32 insertions, 56 deletions
diff --git a/src/cuchaz/enigma/mapping/SignatureUpdater.java b/src/cuchaz/enigma/mapping/SignatureUpdater.java index 809473e..3477cd5 100644 --- a/src/cuchaz/enigma/mapping/SignatureUpdater.java +++ b/src/cuchaz/enigma/mapping/SignatureUpdater.java | |||
| @@ -16,84 +16,63 @@ import java.util.List; | |||
| 16 | 16 | ||
| 17 | import com.google.common.collect.Lists; | 17 | import com.google.common.collect.Lists; |
| 18 | 18 | ||
| 19 | public class SignatureUpdater | 19 | public class SignatureUpdater { |
| 20 | { | 20 | |
| 21 | public interface ClassNameUpdater | 21 | public interface ClassNameUpdater { |
| 22 | { | 22 | String update(String className); |
| 23 | String update( String className ); | ||
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | public static String update( String signature, ClassNameUpdater updater ) | 25 | public static String update(String signature, ClassNameUpdater updater) { |
| 27 | { | 26 | try { |
| 28 | try | ||
| 29 | { | ||
| 30 | StringBuilder buf = new StringBuilder(); | 27 | StringBuilder buf = new StringBuilder(); |
| 31 | 28 | ||
| 32 | // read the signature character-by-character | 29 | // read the signature character-by-character |
| 33 | StringReader reader = new StringReader( signature ); | 30 | StringReader reader = new StringReader(signature); |
| 34 | int i = -1; | 31 | int i = -1; |
| 35 | while( ( i = reader.read() ) != -1 ) | 32 | while ( (i = reader.read()) != -1) { |
| 36 | { | ||
| 37 | char c = (char)i; | 33 | char c = (char)i; |
| 38 | 34 | ||
| 39 | // does this character start a class name? | 35 | // does this character start a class name? |
| 40 | if( c == 'L' ) | 36 | if (c == 'L') { |
| 41 | { | ||
| 42 | // update the class name and add it to the buffer | 37 | // update the class name and add it to the buffer |
| 43 | buf.append( 'L' ); | 38 | buf.append('L'); |
| 44 | String className = readClass( reader ); | 39 | String className = readClass(reader); |
| 45 | if( className == null ) | 40 | if (className == null) { |
| 46 | { | 41 | throw new IllegalArgumentException("Malformed signature: " + signature); |
| 47 | throw new IllegalArgumentException( "Malformed signature: " + signature ); | ||
| 48 | } | 42 | } |
| 49 | buf.append( updater.update( className ) ); | 43 | buf.append(updater.update(className)); |
| 50 | buf.append( ';' ); | 44 | buf.append(';'); |
| 51 | } | 45 | } else { |
| 52 | else | ||
| 53 | { | ||
| 54 | // copy the character into the buffer | 46 | // copy the character into the buffer |
| 55 | buf.append( c ); | 47 | buf.append(c); |
| 56 | } | 48 | } |
| 57 | } | 49 | } |
| 58 | 50 | ||
| 59 | return buf.toString(); | 51 | return buf.toString(); |
| 60 | } | 52 | } catch (IOException ex) { |
| 61 | catch( IOException ex ) | ||
| 62 | { | ||
| 63 | // I'm pretty sure a StringReader will never throw one of these | 53 | // I'm pretty sure a StringReader will never throw one of these |
| 64 | throw new Error( ex ); | 54 | throw new Error(ex); |
| 65 | } | 55 | } |
| 66 | } | 56 | } |
| 67 | 57 | ||
| 68 | private static String readClass( StringReader reader ) | 58 | private static String readClass(StringReader reader) throws IOException { |
| 69 | throws IOException | ||
| 70 | { | ||
| 71 | // read all the characters in the buffer until we hit a ';' | 59 | // read all the characters in the buffer until we hit a ';' |
| 72 | // remember to treat generics correctly | 60 | // remember to treat generics correctly |
| 73 | StringBuilder buf = new StringBuilder(); | 61 | StringBuilder buf = new StringBuilder(); |
| 74 | int depth = 0; | 62 | int depth = 0; |
| 75 | int i = -1; | 63 | int i = -1; |
| 76 | while( ( i = reader.read() ) != -1 ) | 64 | while ( (i = reader.read()) != -1) { |
| 77 | { | ||
| 78 | char c = (char)i; | 65 | char c = (char)i; |
| 79 | 66 | ||
| 80 | if( c == '<' ) | 67 | if (c == '<') { |
| 81 | { | ||
| 82 | depth++; | 68 | depth++; |
| 83 | } | 69 | } else if (c == '>') { |
| 84 | else if( c == '>' ) | ||
| 85 | { | ||
| 86 | depth--; | 70 | depth--; |
| 87 | } | 71 | } else if (depth == 0) { |
| 88 | else if( depth == 0 ) | 72 | if (c == ';') { |
| 89 | { | ||
| 90 | if( c == ';' ) | ||
| 91 | { | ||
| 92 | return buf.toString(); | 73 | return buf.toString(); |
| 93 | } | 74 | } else { |
| 94 | else | 75 | buf.append(c); |
| 95 | { | ||
| 96 | buf.append( c ); | ||
| 97 | } | 76 | } |
| 98 | } | 77 | } |
| 99 | } | 78 | } |
| @@ -101,18 +80,15 @@ public class SignatureUpdater | |||
| 101 | return null; | 80 | return null; |
| 102 | } | 81 | } |
| 103 | 82 | ||
| 104 | public static List<String> getClasses( String signature ) | 83 | public static List<String> getClasses(String signature) { |
| 105 | { | ||
| 106 | final List<String> classNames = Lists.newArrayList(); | 84 | final List<String> classNames = Lists.newArrayList(); |
| 107 | update( signature, new ClassNameUpdater( ) | 85 | update(signature, new ClassNameUpdater() { |
| 108 | { | ||
| 109 | @Override | 86 | @Override |
| 110 | public String update( String className ) | 87 | public String update(String className) { |
| 111 | { | 88 | classNames.add(className); |
| 112 | classNames.add( className ); | ||
| 113 | return className; | 89 | return className; |
| 114 | } | 90 | } |
| 115 | } ); | 91 | }); |
| 116 | return classNames; | 92 | return classNames; |
| 117 | } | 93 | } |
| 118 | } | 94 | } |