Skip to content

Commit d6217a1

Browse files
authored
Correctly source param mappings on missing lvt
Codebook did not correctly respect the difference between parameter and lvt indexing when sourcing parameter names from mappings on missing lvt tables. This caused parameter mappings to appear shifted after long/double params. Reviewed-on: #39
1 parent 3a28fb8 commit d6217a1

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,10 @@ private void fillNames0(final MethodData method) throws IOException {
216216
}
217217

218218
for (int i = 0; i < paramCount; i++) {
219-
// always (i + 1) because abstract methods are never static
220219
final int fi = i;
221220
@Nullable
222221
String paramName = methodMapping
223-
.flatMap(m -> m.getParameterMapping(fi + 1))
222+
.flatMap(m -> m.getParameterMapping(fromParamToLvtIndex(fi, method)))
224223
.map(Mapping::getDeobfuscatedName)
225224
.orElse(null);
226225

@@ -483,4 +482,26 @@ private static int fromLvtToParamIndex(final int lvtIndex, final MethodData meth
483482

484483
return -1;
485484
}
485+
486+
/*
487+
* Transform the given param index into a lvt index.
488+
*/
489+
private static int fromParamToLvtIndex(final int paramIndex, final MethodData method) {
490+
int currentLvtIndex = method.isStatic() ? 0 : 1;
491+
int currentParamIndex = 0;
492+
493+
for (final JvmType param : method.params()) {
494+
if (currentParamIndex == paramIndex) {
495+
return currentLvtIndex;
496+
}
497+
498+
currentParamIndex++;
499+
currentLvtIndex++;
500+
if (param == PrimitiveType.LONG || param == PrimitiveType.DOUBLE) {
501+
currentLvtIndex++;
502+
}
503+
}
504+
505+
return -1;
506+
}
486507
}

0 commit comments

Comments
 (0)