diff options
| author | 2017-05-16 00:24:29 +0200 | |
|---|---|---|
| committer | 2017-05-16 00:24:29 +0200 | |
| commit | b280104d2f926ab74772cef2bf1602663cefa312 (patch) | |
| tree | d130c86a30ec5df37b3a9c4bab576e971ae2e664 /src/main/java/cuchaz/enigma/convert/MatchesWriter.java | |
| parent | Add offset for Enum constructor arguments (Fix #58) (diff) | |
| download | enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.tar.gz enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.tar.xz enigma-fork-b280104d2f926ab74772cef2bf1602663cefa312.zip | |
Remove the converter + some reorganization
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MatchesWriter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/MatchesWriter.java | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java b/src/main/java/cuchaz/enigma/convert/MatchesWriter.java deleted file mode 100644 index 8fe7326..0000000 --- a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java +++ /dev/null | |||
| @@ -1,123 +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.convert; | ||
| 13 | |||
| 14 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 15 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 16 | import cuchaz.enigma.mapping.Entry; | ||
| 17 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 18 | |||
| 19 | import java.io.File; | ||
| 20 | import java.io.FileOutputStream; | ||
| 21 | import java.io.IOException; | ||
| 22 | import java.io.OutputStreamWriter; | ||
| 23 | import java.nio.charset.Charset; | ||
| 24 | import java.util.Map; | ||
| 25 | |||
| 26 | public class MatchesWriter { | ||
| 27 | |||
| 28 | public static void writeClasses(ClassMatches matches, File file) | ||
| 29 | throws IOException { | ||
| 30 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { | ||
| 31 | for (ClassMatch match : matches) { | ||
| 32 | writeClassMatch(out, match); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | private static void writeClassMatch(OutputStreamWriter out, ClassMatch match) | ||
| 38 | throws IOException { | ||
| 39 | writeClasses(out, match.sourceClasses); | ||
| 40 | out.write(":"); | ||
| 41 | writeClasses(out, match.destClasses); | ||
| 42 | out.write("\n"); | ||
| 43 | } | ||
| 44 | |||
| 45 | private static void writeClasses(OutputStreamWriter out, Iterable<ClassEntry> classes) | ||
| 46 | throws IOException { | ||
| 47 | boolean isFirst = true; | ||
| 48 | for (ClassEntry entry : classes) { | ||
| 49 | if (isFirst) { | ||
| 50 | isFirst = false; | ||
| 51 | } else { | ||
| 52 | out.write(","); | ||
| 53 | } | ||
| 54 | out.write(entry.toString()); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file) | ||
| 59 | throws IOException { | ||
| 60 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { | ||
| 61 | for (Map.Entry<T, T> match : matches.matches().entrySet()) { | ||
| 62 | writeMemberMatch(out, match.getKey(), match.getValue()); | ||
| 63 | } | ||
| 64 | for (T entry : matches.getUnmatchedSourceEntries()) { | ||
| 65 | writeMemberMatch(out, entry, null); | ||
| 66 | } | ||
| 67 | for (T entry : matches.getUnmatchedDestEntries()) { | ||
| 68 | writeMemberMatch(out, null, entry); | ||
| 69 | } | ||
| 70 | for (T entry : matches.getUnmatchableSourceEntries()) { | ||
| 71 | writeUnmatchableEntry(out, entry); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | private static <T extends Entry> void writeMemberMatch(OutputStreamWriter out, T source, T dest) | ||
| 77 | throws IOException { | ||
| 78 | if (source != null) { | ||
| 79 | writeEntry(out, source); | ||
| 80 | } | ||
| 81 | out.write(":"); | ||
| 82 | if (dest != null) { | ||
| 83 | writeEntry(out, dest); | ||
| 84 | } | ||
| 85 | out.write("\n"); | ||
| 86 | } | ||
| 87 | |||
| 88 | private static <T extends Entry> void writeUnmatchableEntry(OutputStreamWriter out, T entry) | ||
| 89 | throws IOException { | ||
| 90 | out.write("!"); | ||
| 91 | writeEntry(out, entry); | ||
| 92 | out.write("\n"); | ||
| 93 | } | ||
| 94 | |||
| 95 | private static <T extends Entry> void writeEntry(OutputStreamWriter out, T entry) | ||
| 96 | throws IOException { | ||
| 97 | if (entry instanceof FieldEntry) { | ||
| 98 | writeField(out, (FieldEntry) entry); | ||
| 99 | } else if (entry instanceof BehaviorEntry) { | ||
| 100 | writeBehavior(out, (BehaviorEntry) entry); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | private static void writeField(OutputStreamWriter out, FieldEntry fieldEntry) | ||
| 105 | throws IOException { | ||
| 106 | out.write(fieldEntry.getClassName()); | ||
| 107 | out.write(" "); | ||
| 108 | out.write(fieldEntry.getName()); | ||
| 109 | out.write(" "); | ||
| 110 | out.write(fieldEntry.getType().toString()); | ||
| 111 | } | ||
| 112 | |||
| 113 | private static void writeBehavior(OutputStreamWriter out, BehaviorEntry behaviorEntry) | ||
| 114 | throws IOException { | ||
| 115 | out.write(behaviorEntry.getClassName()); | ||
| 116 | out.write(" "); | ||
| 117 | out.write(behaviorEntry.getName()); | ||
| 118 | out.write(" "); | ||
| 119 | if (behaviorEntry.getSignature() != null) { | ||
| 120 | out.write(behaviorEntry.getSignature().toString()); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||