refactor: port ScalaSignature byte sections to Java

This commit is contained in:
Algent committed 2026-09-04 18:07:00 +02:00
1 parent 13de853ff2
commit 37699ba73d
5 files changed
+45 -13

No files matched your search

@@ -9,7 +9,7 @@ object ScalaSignature {
case class Bytes(arr: Array[Byte], pos: Int, len: Int) {
def reader = new ByteCodeReader(this)
def section = arr.drop(pos).take(len)
def section = ScalaSignatureParser.section(this)
}
trait Flags {
@@ -1,5 +1,6 @@
package codechicken.multipart.asm;
import java.util.Arrays;
import java.util.Objects;
import codechicken.multipart.asm.ScalaSignature.Bytes;
@@ -19,6 +20,15 @@ final class ScalaSignatureParser {
private ScalaSignatureParser() {}
static byte[] section(Bytes bytes) {
byte[] array = bytes.arr();
int start = bytes.pos();
start = Math.min(array.length, Math.max(0, start));
// Snapshot before len(): an override can mutate the original array.
byte[] remaining = Arrays.copyOfRange(array, start, array.length);
return Arrays.copyOf(remaining, Math.min(remaining.length, Math.max(0, bytes.len())));
}
// Keep path-dependent model types out of signatures read by Scala 2.11's Java parser.
static Object readTable(ScalaSignature sig, Bytes bytes) {
ByteCodeReader reader = bytes.reader();