Skip to content

Commit 047c8f3

Browse files
committed
Fix support for default package classes in Proguard loader. Closes #20
Fix Tiny v2 variable comments causing loading error. Closes #21
1 parent 917096e commit 047c8f3

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

src/main/java/net/minecraftforge/srgutils/InternalUtils.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private static IMappingBuilder loadTinyV2(List<String> lines) throws IOException
441441
if (newdepth != 0)
442442
line = line.substring(newdepth);
443443

444-
if (newdepth != stack.size()) {
444+
if (newdepth <= stack.size()) {
445445
while (stack.size() != newdepth) {
446446
switch(stack.pop()) {
447447
case CLASS: cls = null; break;
@@ -451,6 +451,8 @@ private static IMappingBuilder loadTinyV2(List<String> lines) throws IOException
451451
default: break;
452452
}
453453
}
454+
} else {
455+
throw tiny2Exception(x, line);
454456
}
455457

456458
String[] parts = line.split("\t");
@@ -486,6 +488,8 @@ private static IMappingBuilder loadTinyV2(List<String> lines) throws IOException
486488
if (param == null) throw tiny2Exception(x, line);
487489
param.meta("comment", comment);
488490
break;
491+
case VARIABLE:
492+
break; // TODO: [SRGUtils][LocalVariables] Support LocalVariable comments in Mapping files
489493
default:
490494
throw tiny2Exception(x, line);
491495
}
@@ -518,17 +522,18 @@ private static IMappingBuilder loadTinyV2(List<String> lines) throws IOException
518522

519523
break;
520524
case "v": // Local Variable: v index start Name1 Name2 Name3?
521-
break; //TODO: Unsupported, is this used? Should we expose it?
525+
stack.push(TinyV2State.VARIABLE);
526+
break; // TODO: [SRGUtils][LocalVariables] Support LocalVariables in Mapping files
522527
default:
523528
throw tiny2Exception(x, line);
524529
}
525530
}
526531

527532
return ret;
528533
}
529-
enum TinyV2State { ROOT, CLASS, FIELD, METHOD, PARAMETER }
534+
enum TinyV2State { ROOT, CLASS, FIELD, METHOD, PARAMETER, VARIABLE }
530535
private static IOException tiny2Exception(int line, String data) {
531-
return new IOException("Invalid Tiny v2 line: #" + line + ": " + data);
536+
return new IOException("Invalid Tiny v2 line: #" + (line + 1) + ": " + data);
532537
}
533538

534539
/* <escaped-string> is a string that must not contain <eol> and escapes
@@ -565,8 +570,7 @@ static String toDesc(String type) {
565570
if (type.equals("double")) return "D";
566571
if (type.equals("float")) return "F";
567572
if (type.equals("long")) return "J";
568-
if (type.contains("/")) return "L" + type + ";";
569-
throw new RuntimeException("Invalid toDesc input: " + type);
573+
return "L" + type + ";";
570574
}
571575

572576
static String toSource(String desc) {

src/test/java/net/minecraftforge/srgutils/test/MappingTest.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import net.minecraftforge.srgutils.IMappingBuilder;
2020
import net.minecraftforge.srgutils.IMappingFile;
21-
import net.minecraftforge.srgutils.IMappingFile.Format;
21+
import net.minecraftforge.srgutils.IMappingFile.Format;
22+
import net.minecraftforge.srgutils.IMappingFile.IClass;
23+
import net.minecraftforge.srgutils.IMappingFile.IField;
24+
import net.minecraftforge.srgutils.IMappingFile.IMethod;
2225
import net.minecraftforge.srgutils.INamedMappingFile;
2326

2427
import static org.junit.jupiter.api.Assertions.*;
@@ -135,8 +138,37 @@ void tinyV2PackageComments() throws IOException {
135138

136139
@Test
137140
void tinyV2NamedLoad() throws IOException {
138-
INamedMappingFile map = INamedMappingFile.load(getStream("./tiny_v2_named.tiny"));
139-
assertIterableEquals(Arrays.asList("A", "B", "C"), map.getNames());
141+
INamedMappingFile named = INamedMappingFile.load(getStream("./tiny_v2_named.tiny"));
142+
assertIterableEquals(Arrays.asList("A", "B", "C"), named.getNames());
143+
tinyV2NamedTest(named, "A", "B");
144+
tinyV2NamedTest(named, "A", "C");
145+
tinyV2NamedTest(named, "B", "A");
146+
tinyV2NamedTest(named, "B", "C");
147+
tinyV2NamedTest(named, "C", "B");
148+
tinyV2NamedTest(named, "C", "A");
149+
}
150+
151+
void tinyV2NamedTest(INamedMappingFile named, String left, String right) {
152+
IMappingFile map = named.getMap(left, right);
153+
IClass cls = map.getClass("cls" + left);
154+
assertNotNull(cls, "Could not find cls" + left + " in " + left + " -> " + right);
155+
assertEquals("cls" + right, cls.getMapped());
156+
157+
IField fld = cls.getField("fld" + left);
158+
assertNotNull(cls, "Could not find fld" + left + " in " + left + " -> " + right);
159+
assertEquals("fld" + right, fld.getMapped());
160+
161+
IMethod mtd = cls.getMethod("mtd" + left, "()Lcls" + left + ';');
162+
assertNotNull(cls, "Could not find mtd" + left + " in " + left + " -> " + right);
163+
assertEquals("mtd" + right, mtd.getMapped());
164+
assertEquals("()Lcls" + right + ';', mtd.getMappedDescriptor());
165+
}
166+
167+
@Test
168+
void tinyV2OptionalAndLVs() throws IOException {
169+
INamedMappingFile named = INamedMappingFile.load(getStream("./tiny_v2_09_2024_edition.tiny"));
170+
assertIterableEquals(Arrays.asList("source", "same", "rename"), named.getNames());
171+
140172
}
141173

142174
@Test

src/test/resources/tiny_v2_named.tiny

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ c clsA clsB clsC
66
m ()LclsA; mtdA mtdB mtdC
77
c Method Comment
88
p 1 parA parB parC
9-
c Param Comment
9+
c Param Comment
10+
v 1 1 1 varA varB varC
11+
c A varaible comment this would trigger https://github.com/MinecraftForge/SrgUtils/issues/21

0 commit comments

Comments
 (0)