diff --git a/src/main/java/net/fabricmc/mappingio/MappingReader.java b/src/main/java/net/fabricmc/mappingio/MappingReader.java index 93b5f22d..3b1609d1 100644 --- a/src/main/java/net/fabricmc/mappingio/MappingReader.java +++ b/src/main/java/net/fabricmc/mappingio/MappingReader.java @@ -29,6 +29,7 @@ import net.fabricmc.mappingio.format.EnigmaReader; import net.fabricmc.mappingio.format.MappingFormat; import net.fabricmc.mappingio.format.ProGuardReader; +import net.fabricmc.mappingio.format.SimpleReader; import net.fabricmc.mappingio.format.SrgReader; import net.fabricmc.mappingio.format.Tiny1Reader; import net.fabricmc.mappingio.format.Tiny2Reader; @@ -187,6 +188,9 @@ public static void read(Reader reader, MappingFormat format, MappingVisitor visi case PROGUARD: ProGuardReader.read(reader, visitor); break; + case SIMPLE: + SimpleReader.read(reader, visitor); + break; default: throw new IllegalStateException(); } diff --git a/src/main/java/net/fabricmc/mappingio/format/MappingFormat.java b/src/main/java/net/fabricmc/mappingio/format/MappingFormat.java index ce8ae97f..03b8164e 100644 --- a/src/main/java/net/fabricmc/mappingio/format/MappingFormat.java +++ b/src/main/java/net/fabricmc/mappingio/format/MappingFormat.java @@ -24,7 +24,8 @@ public enum MappingFormat { 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); + PROGUARD("ProGuard", "map", false, true, false, false, false), + SIMPLE("Simple", "txt", false, false, false, false, false); MappingFormat(String name, String fileExt, boolean hasNamespaces, boolean hasFieldDescriptors, diff --git a/src/main/java/net/fabricmc/mappingio/format/SimpleReader.java b/src/main/java/net/fabricmc/mappingio/format/SimpleReader.java new file mode 100644 index 00000000..a0284d2f --- /dev/null +++ b/src/main/java/net/fabricmc/mappingio/format/SimpleReader.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.mappingio.format; + +import net.fabricmc.mappingio.MappedElementKind; +import net.fabricmc.mappingio.MappingVisitor; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; + +public final class SimpleReader { + + public static void read(Reader reader, MappingVisitor visitor) throws IOException { + BufferedReader br = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); + read(br, visitor); + } + + public static void read(BufferedReader reader, MappingVisitor visitor) throws IOException { + String line; + while ((line = reader.readLine()) != null) { + + String[] split = line.split(" "); + String obf = split[0]; + String deobf = split[1]; + + if (!(line.contains(".") || line.contains("("))) { + if (visitor.visitClass(obf)) { + visitor.visitDstName(MappedElementKind.CLASS, 0, deobf); + visitor.visitElementContent(MappedElementKind.CLASS); + } + } else if (line.contains(".") && !line.contains("(")) { + if (visitor.visitField(obf.substring(obf.lastIndexOf(".") + 1), null)) { + visitor.visitDstName(MappedElementKind.FIELD, 0, deobf); + visitor.visitElementContent(MappedElementKind.FIELD); + } + } else if (line.contains(".") && line.contains("(")) { + if (visitor.visitMethod(obf.substring(obf.lastIndexOf(".") + 1, obf.lastIndexOf("(")), obf.substring(obf.lastIndexOf("(")))) { + visitor.visitDstName(MappedElementKind.METHOD, 0, deobf); + visitor.visitElementContent(MappedElementKind.METHOD); + } + } + } + } +}