diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/MappingsWriter.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsWriter.java | 110 |
1 files changed, 38 insertions, 72 deletions
diff --git a/src/cuchaz/enigma/mapping/MappingsWriter.java b/src/cuchaz/enigma/mapping/MappingsWriter.java index 3c86dfc..5ac409f 100644 --- a/src/cuchaz/enigma/mapping/MappingsWriter.java +++ b/src/cuchaz/enigma/mapping/MappingsWriter.java | |||
| @@ -17,105 +17,71 @@ import java.util.ArrayList; | |||
| 17 | import java.util.Collections; | 17 | import java.util.Collections; |
| 18 | import java.util.List; | 18 | import java.util.List; |
| 19 | 19 | ||
| 20 | public class MappingsWriter | 20 | public class MappingsWriter { |
| 21 | { | 21 | |
| 22 | public void write( Writer out, Mappings mappings ) | 22 | public void write(Writer out, Mappings mappings) throws IOException { |
| 23 | throws IOException | 23 | write(new PrintWriter(out), mappings); |
| 24 | { | ||
| 25 | write( new PrintWriter( out ), mappings ); | ||
| 26 | } | 24 | } |
| 27 | 25 | ||
| 28 | public void write( PrintWriter out, Mappings mappings ) | 26 | public void write(PrintWriter out, Mappings mappings) throws IOException { |
| 29 | throws IOException | 27 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 30 | { | 28 | write(out, classMapping, 0); |
| 31 | for( ClassMapping classMapping : sorted( mappings.classes() ) ) | ||
| 32 | { | ||
| 33 | write( out, classMapping, 0 ); | ||
| 34 | } | 29 | } |
| 35 | } | 30 | } |
| 36 | 31 | ||
| 37 | private void write( PrintWriter out, ClassMapping classMapping, int depth ) | 32 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { |
| 38 | throws IOException | 33 | if (classMapping.getDeobfName() == null) { |
| 39 | { | 34 | out.format("%sCLASS %s\n", getIndent(depth), classMapping.getObfName()); |
| 40 | if( classMapping.getDeobfName() == null ) | 35 | } else { |
| 41 | { | 36 | out.format("%sCLASS %s %s\n", getIndent(depth), classMapping.getObfName(), classMapping.getDeobfName()); |
| 42 | out.format( "%sCLASS %s\n", getIndent( depth ), classMapping.getObfName() ); | ||
| 43 | } | ||
| 44 | else | ||
| 45 | { | ||
| 46 | out.format( "%sCLASS %s %s\n", getIndent( depth ), classMapping.getObfName(), classMapping.getDeobfName() ); | ||
| 47 | } | 37 | } |
| 48 | 38 | ||
| 49 | for( ClassMapping innerClassMapping : sorted( classMapping.innerClasses() ) ) | 39 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { |
| 50 | { | 40 | write(out, innerClassMapping, depth + 1); |
| 51 | write( out, innerClassMapping, depth + 1 ); | ||
| 52 | } | 41 | } |
| 53 | 42 | ||
| 54 | for( FieldMapping fieldMapping : sorted( classMapping.fields() ) ) | 43 | for (FieldMapping fieldMapping : sorted(classMapping.fields())) { |
| 55 | { | 44 | write(out, fieldMapping, depth + 1); |
| 56 | write( out, fieldMapping, depth + 1 ); | ||
| 57 | } | 45 | } |
| 58 | 46 | ||
| 59 | for( MethodMapping methodMapping : sorted( classMapping.methods() ) ) | 47 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { |
| 60 | { | 48 | write(out, methodMapping, depth + 1); |
| 61 | write( out, methodMapping, depth + 1 ); | ||
| 62 | } | 49 | } |
| 63 | } | 50 | } |
| 64 | 51 | ||
| 65 | private void write( PrintWriter out, FieldMapping fieldMapping, int depth ) | 52 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException { |
| 66 | throws IOException | 53 | out.format("%sFIELD %s %s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName()); |
| 67 | { | ||
| 68 | out.format( "%sFIELD %s %s\n", getIndent( depth ), fieldMapping.getObfName(), fieldMapping.getDeobfName() ); | ||
| 69 | } | 54 | } |
| 70 | 55 | ||
| 71 | private void write( PrintWriter out, MethodMapping methodMapping, int depth ) | 56 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { |
| 72 | throws IOException | 57 | if (methodMapping.getDeobfName() == null) { |
| 73 | { | 58 | out.format("%sMETHOD %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 74 | if( methodMapping.getDeobfName() == null ) | 59 | } else { |
| 75 | { | 60 | out.format("%sMETHOD %s %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature()); |
| 76 | out.format( "%sMETHOD %s %s\n", | ||
| 77 | getIndent( depth ), | ||
| 78 | methodMapping.getObfName(), methodMapping.getObfSignature() | ||
| 79 | ); | ||
| 80 | } | ||
| 81 | else | ||
| 82 | { | ||
| 83 | out.format( "%sMETHOD %s %s %s\n", | ||
| 84 | getIndent( depth ), | ||
| 85 | methodMapping.getObfName(), methodMapping.getDeobfName(), | ||
| 86 | methodMapping.getObfSignature() | ||
| 87 | ); | ||
| 88 | } | 61 | } |
| 89 | 62 | ||
| 90 | for( ArgumentMapping argumentMapping : sorted( methodMapping.arguments() ) ) | 63 | for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { |
| 91 | { | 64 | write(out, argumentMapping, depth + 1); |
| 92 | write( out, argumentMapping, depth + 1 ); | ||
| 93 | } | 65 | } |
| 94 | } | 66 | } |
| 95 | 67 | ||
| 96 | private void write( PrintWriter out, ArgumentMapping argumentMapping, int depth ) | 68 | private void write(PrintWriter out, ArgumentMapping argumentMapping, int depth) throws IOException { |
| 97 | throws IOException | 69 | out.format("%sARG %d %s\n", getIndent(depth), argumentMapping.getIndex(), argumentMapping.getName()); |
| 98 | { | ||
| 99 | out.format( "%sARG %d %s\n", getIndent( depth ), argumentMapping.getIndex(), argumentMapping.getName() ); | ||
| 100 | } | 70 | } |
| 101 | 71 | ||
| 102 | private <T extends Comparable<T>> List<T> sorted( Iterable<T> classes ) | 72 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { |
| 103 | { | ||
| 104 | List<T> out = new ArrayList<T>(); | 73 | List<T> out = new ArrayList<T>(); |
| 105 | for( T t : classes ) | 74 | for (T t : classes) { |
| 106 | { | 75 | out.add(t); |
| 107 | out.add( t ); | ||
| 108 | } | 76 | } |
| 109 | Collections.sort( out ); | 77 | Collections.sort(out); |
| 110 | return out; | 78 | return out; |
| 111 | } | 79 | } |
| 112 | 80 | ||
| 113 | private String getIndent( int depth ) | 81 | private String getIndent(int depth) { |
| 114 | { | ||
| 115 | StringBuilder buf = new StringBuilder(); | 82 | StringBuilder buf = new StringBuilder(); |
| 116 | for( int i=0; i<depth; i++ ) | 83 | for (int i = 0; i < depth; i++) { |
| 117 | { | 84 | buf.append("\t"); |
| 118 | buf.append( "\t" ); | ||
| 119 | } | 85 | } |
| 120 | return buf.toString(); | 86 | return buf.toString(); |
| 121 | } | 87 | } |