Skip to content

Commit

Permalink
Consistently apply FILE and DIR naming for mapping formats
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed May 13, 2023
1 parent bde4aa5 commit a6de335
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 73 deletions.
66 changes: 33 additions & 33 deletions src/main/java/net/fabricmc/mappingio/MappingReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.enigma.EnigmaDirReader;
import net.fabricmc.mappingio.format.enigma.EnigmaReader;
import net.fabricmc.mappingio.format.proguard.ProGuardReader;
import net.fabricmc.mappingio.format.srg.SrgReader;
import net.fabricmc.mappingio.format.tiny.Tiny1Reader;
import net.fabricmc.mappingio.format.tiny.Tiny2Reader;
import net.fabricmc.mappingio.format.tsrg.TsrgReader;
import net.fabricmc.mappingio.format.enigma.EnigmaFileReader;
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader;
import net.fabricmc.mappingio.format.srg.SrgFileReader;
import net.fabricmc.mappingio.format.tiny.Tiny1FileReader;
import net.fabricmc.mappingio.format.tiny.Tiny2FileReader;
import net.fabricmc.mappingio.format.tsrg.TsrgFileReader;

public final class MappingReader {
public static MappingFormat detectFormat(Path file) throws IOException {
Expand All @@ -60,26 +60,26 @@ public static MappingFormat detectFormat(Reader reader) throws IOException {

switch (String.valueOf(buffer, 0, 3)) {
case "v1\t":
return MappingFormat.TINY;
return MappingFormat.TINY_FILE;
case "tin":
return MappingFormat.TINY_2;
return MappingFormat.TINY_2_FILE;
case "tsr": // tsrg2 <nsA> <nsB> ..<nsN>
return MappingFormat.TSRG2;
return MappingFormat.TSRG_2_FILE;
case "CLA":
return MappingFormat.ENIGMA;
return MappingFormat.ENIGMA_FILE;
case "PK:":
case "CL:":
case "MD:":
case "FD:":
return MappingFormat.SRG;
return MappingFormat.SRG_FILE;
}

String headerStr = String.valueOf(buffer, 0, pos);

if (headerStr.contains(" -> ")) {
return MappingFormat.PROGUARD;
return MappingFormat.PROGUARD_FILE;
} else if (headerStr.contains("\n\t")) {
return MappingFormat.TSRG;
return MappingFormat.TSRG_FILE;
}

return null; // unknown format or corrupted
Expand Down Expand Up @@ -119,12 +119,12 @@ public static List<String> getNamespaces(Reader reader, MappingFormat format) th

if (format.hasNamespaces) {
switch (format) {
case TINY:
return Tiny1Reader.getNamespaces(reader);
case TINY_2:
return Tiny2Reader.getNamespaces(reader);
case TSRG2:
return TsrgReader.getNamespaces(reader);
case TINY_FILE:
return Tiny1FileReader.getNamespaces(reader);
case TINY_2_FILE:
return Tiny2FileReader.getNamespaces(reader);
case TSRG_2_FILE:
return TsrgFileReader.getNamespaces(reader);
default:
throw new IllegalStateException();
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public static void read(Path file, MappingFormat format, MappingVisitor visitor)
case ENIGMA_DIR:
EnigmaDirReader.read(file, visitor);
break;
case MCP:
case MCP_DIR:
throw new UnsupportedOperationException(); // TODO: implement
default:
throw new IllegalStateException();
Expand All @@ -174,24 +174,24 @@ public static void read(Reader reader, MappingFormat format, MappingVisitor visi
}

switch (format) {
case TINY:
Tiny1Reader.read(reader, visitor);
case TINY_FILE:
Tiny1FileReader.read(reader, visitor);
break;
case TINY_2:
Tiny2Reader.read(reader, visitor);
case TINY_2_FILE:
Tiny2FileReader.read(reader, visitor);
break;
case ENIGMA:
EnigmaReader.read(reader, visitor);
case ENIGMA_FILE:
EnigmaFileReader.read(reader, visitor);
break;
case SRG:
SrgReader.read(reader, visitor);
case SRG_FILE:
SrgFileReader.read(reader, visitor);
break;
case TSRG:
case TSRG2:
TsrgReader.read(reader, visitor);
case TSRG_FILE:
case TSRG_2_FILE:
TsrgFileReader.read(reader, visitor);
break;
case PROGUARD:
ProGuardReader.read(reader, visitor);
case PROGUARD_FILE:
ProGuardFileReader.read(reader, visitor);
break;
default:
throw new IllegalStateException();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/fabricmc/mappingio/MappingWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.enigma.EnigmaDirWriter;
import net.fabricmc.mappingio.format.enigma.EnigmaWriter;
import net.fabricmc.mappingio.format.tiny.Tiny1Writer;
import net.fabricmc.mappingio.format.tiny.Tiny2Writer;
import net.fabricmc.mappingio.format.enigma.EnigmaFileWriter;
import net.fabricmc.mappingio.format.tiny.Tiny1FileWriter;
import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter;

public interface MappingWriter extends Closeable, MappingVisitor {
static MappingWriter create(Path file, MappingFormat format) throws IOException {
Expand All @@ -44,9 +44,9 @@ static MappingWriter create(Writer writer, MappingFormat format) throws IOExcept
if (!format.hasSingleFile()) throw new IllegalArgumentException("format "+format+" is not applicable to a single writer");

switch (format) {
case TINY: return new Tiny1Writer(writer);
case TINY_2: return new Tiny2Writer(writer, false);
case ENIGMA: return new EnigmaWriter(writer);
case TINY_FILE: return new Tiny1FileWriter(writer);
case TINY_2_FILE: return new Tiny2FileWriter(writer, false);
case ENIGMA_FILE: return new EnigmaFileWriter(writer);
default: throw new UnsupportedOperationException("format "+format+" is not implemented");
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/fabricmc/mappingio/format/MappingFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package net.fabricmc.mappingio.format;

public enum MappingFormat {
TINY("Tiny", "tiny", true, true, false, false, false),
TINY_2("Tiny v2", "tiny", true, true, true, true, true),
ENIGMA("Enigma", "mapping", false, true, true, true, false),
TINY_FILE("Tiny file", "tiny", true, true, false, false, false),
TINY_2_FILE("Tiny v2 file", "tiny", true, true, true, true, true),
ENIGMA_FILE("Enigma file", "mapping", false, true, true, true, false),
ENIGMA_DIR("Enigma directory", null, false, true, true, true, false),
MCP("MCP", null, false, false, true, true, false),
SRG("SRG", "srg", false, false, false, false, false),
TSRG("TSRG", "tsrg", false, false, false, false, false),
TSRG2("TSRG2", "tsrg", true, false, false, true, false),
PROGUARD("ProGuard", "map", false, true, false, false, false);
MCP_DIR("MCP directory", null, false, false, true, true, false),
SRG_FILE("SRG file", "srg", false, false, false, false, false),
TSRG_FILE("TSRG file", "tsrg", false, false, false, false, false),
TSRG_2_FILE("TSRG2 file", "tsrg", true, false, false, true, false),
PROGUARD_FILE("ProGuard file", "map", false, true, false, false, false);

MappingFormat(String name, String fileExt,
boolean hasNamespaces, boolean hasFieldDescriptors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void read(Path dir, String sourceNs, String targetNs, MappingVisit
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith("." + MappingFormat.ENIGMA.fileExt)) {
EnigmaReader.read(Files.newBufferedReader(file), sourceNs, targetNs, visitor);
if (file.getFileName().toString().endsWith("." + MappingFormat.ENIGMA_FILE.fileExt)) {
EnigmaFileReader.read(Files.newBufferedReader(file), sourceNs, targetNs, visitor);
}

return FileVisitResult.CONTINUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public EnigmaDirWriter(Path dir, boolean deleteExistingFiles) throws IOException
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith("." + MappingFormat.ENIGMA.fileExt)) {
if (file.getFileName().toString().endsWith("." + MappingFormat.ENIGMA_FILE.fileExt)) {
Files.delete(file);
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public boolean visitElementContent(MappedElementKind targetKind) throws IOExcept
if (pos >= 0) name = name.substring(0, pos);

// currentClass is not an outer class of srcName (or the same)
Path file = dir.resolve(name + "." + MappingFormat.ENIGMA.fileExt).normalize();
Path file = dir.resolve(name + "." + MappingFormat.ENIGMA_FILE.fileExt).normalize();
if (!file.startsWith(dir)) throw new RuntimeException("invalid name: " + name);

if (writer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public final class EnigmaReader {
public final class EnigmaFileReader {
public static void read(Reader reader, MappingVisitor visitor) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import net.fabricmc.mappingio.MappedElementKind;

public final class EnigmaWriter extends EnigmaWriterBase {
public EnigmaWriter(Writer writer) throws IOException {
public final class EnigmaFileWriter extends EnigmaWriterBase {
public EnigmaFileWriter(Writer writer) throws IOException {
super(writer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import net.fabricmc.mappingio.MappingUtil;
import net.fabricmc.mappingio.MappingVisitor;

public final class ProGuardReader {
public final class ProGuardFileReader {
public static void read(Reader reader, MappingVisitor visitor) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @see <a href="https://www.guardsquare.com/manual/tools/retrace">Official format documentation</a>
*/
public final class ProGuardWriter implements MappingWriter {
public final class ProGuardFileWriter implements MappingWriter {
private final Writer writer;
private int dstNamespace = -1;
private final String dstNamespaceString;
Expand All @@ -45,7 +45,7 @@ public final class ProGuardWriter implements MappingWriter {
*
* @param writer the writer where the mappings will be written
*/
public ProGuardWriter(Writer writer) {
public ProGuardFileWriter(Writer writer) {
this(writer, 0);
}

Expand All @@ -55,7 +55,7 @@ public ProGuardWriter(Writer writer) {
* @param writer the writer where the mappings will be written
* @param dstNamespace the namespace index to write as the destination namespace, must be at least 0
*/
public ProGuardWriter(Writer writer, int dstNamespace) {
public ProGuardFileWriter(Writer writer, int dstNamespace) {
this.writer = Objects.requireNonNull(writer, "writer cannot be null");
this.dstNamespace = dstNamespace;
this.dstNamespaceString = null;
Expand All @@ -71,7 +71,7 @@ public ProGuardWriter(Writer writer, int dstNamespace) {
* @param writer the writer where the mappings will be written
* @param dstNamespace the namespace name to write as the destination namespace
*/
public ProGuardWriter(Writer writer, String dstNamespace) {
public ProGuardFileWriter(Writer writer, String dstNamespace) {
this.writer = Objects.requireNonNull(writer, "writer cannot be null");
this.dstNamespaceString = Objects.requireNonNull(dstNamespace, "namespace cannot be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public final class SrgReader {
public final class SrgFileReader {
public static void read(Reader reader, MappingVisitor visitor) throws IOException {
read(reader, MappingUtil.NS_SOURCE_FALLBACK, MappingUtil.NS_TARGET_FALLBACK, visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public final class Tiny1Reader {
public final class Tiny1FileReader {
public static List<String> getNamespaces(Reader reader) throws IOException {
return getNamespaces(new ColumnFileReader(reader, '\t'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingWriter;

public final class Tiny1Writer implements MappingWriter {
public Tiny1Writer(Writer writer) {
public final class Tiny1FileWriter implements MappingWriter {
public Tiny1FileWriter(Writer writer) {
this.writer = writer;
}

Expand Down Expand Up @@ -60,19 +60,19 @@ public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) thr
@Override
public void visitMetadata(String key, String value) throws IOException {
switch (key) {
case Tiny1Reader.nextIntermediaryClassProperty:
case Tiny1Reader.nextIntermediaryFieldProperty:
case Tiny1Reader.nextIntermediaryMethodProperty:
case Tiny1FileReader.nextIntermediaryClassProperty:
case Tiny1FileReader.nextIntermediaryFieldProperty:
case Tiny1FileReader.nextIntermediaryMethodProperty:
write("# INTERMEDIARY-COUNTER ");

switch (key) {
case Tiny1Reader.nextIntermediaryClassProperty:
case Tiny1FileReader.nextIntermediaryClassProperty:
write("class");
break;
case Tiny1Reader.nextIntermediaryFieldProperty:
case Tiny1FileReader.nextIntermediaryFieldProperty:
write("field");
break;
case Tiny1Reader.nextIntermediaryMethodProperty:
case Tiny1FileReader.nextIntermediaryMethodProperty:
write("method");
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;

public final class Tiny2Reader {
public final class Tiny2FileReader {
public static List<String> getNamespaces(Reader reader) throws IOException {
return getNamespaces(new ColumnFileReader(reader, '\t'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import net.fabricmc.mappingio.MappingFlag;
import net.fabricmc.mappingio.MappingWriter;

public final class Tiny2Writer implements MappingWriter {
public Tiny2Writer(Writer writer, boolean escapeNames) {
public final class Tiny2FileWriter implements MappingWriter {
public Tiny2FileWriter(Writer writer, boolean escapeNames) {
this.writer = writer;
this.escapeNames = escapeNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.format.ColumnFileReader;

public final class TsrgReader {
public final class TsrgFileReader {
public static List<String> getNamespaces(Reader reader) throws IOException {
return getNamespaces(new ColumnFileReader(reader, ' '));
}
Expand Down

0 comments on commit a6de335

Please sign in to comment.