From d9ad6690aa40e4a1d6cb2b494624fbd04b3ba268 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Fri, 15 Sep 2023 14:46:54 -0700 Subject: [PATCH] Use turbine's own class file parser in a test To fix a test failure on JDK 22, which ASM doesn't support yet. PiperOrigin-RevId: 565784119 --- .../bytecode/sig/SigIntegrationTest.java | 77 +++++++------------ 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/javatests/com/google/turbine/bytecode/sig/SigIntegrationTest.java b/javatests/com/google/turbine/bytecode/sig/SigIntegrationTest.java index 58c0effa..b90b0cff 100644 --- a/javatests/com/google/turbine/bytecode/sig/SigIntegrationTest.java +++ b/javatests/com/google/turbine/bytecode/sig/SigIntegrationTest.java @@ -23,7 +23,8 @@ import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; -import org.objectweb.asm.Opcodes; +import com.google.turbine.bytecode.ClassFile; +import com.google.turbine.bytecode.ClassReader; import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; @@ -41,10 +42,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.MethodVisitor; /** * Reads all field, class, and method signatures in the bootclasspath, and round-trips them through @@ -92,51 +89,31 @@ public void roundTrip() throws Exception { forEachBootclass( path -> { try { - new ClassReader(Files.newInputStream(path)) - .accept( - new ClassVisitor(Opcodes.ASM9) { - @Override - public void visit( - int version, - int access, - String name, - String signature, - String superName, - String[] interfaces) { - if (signature != null) { - assertThat(SigWriter.classSig(new SigParser(signature).parseClassSig())) - .isEqualTo(signature); - totalSignatures[0]++; - } - } - - @Override - public FieldVisitor visitField( - int access, String name, String desc, String signature, Object value) { - if (signature != null) { - assertThat(SigWriter.type(new SigParser(signature).parseFieldSig())) - .isEqualTo(signature); - totalSignatures[0]++; - } - return super.visitField(access, name, desc, signature, value); - } - - @Override - public MethodVisitor visitMethod( - int access, - String name, - String desc, - String signature, - String[] exceptions) { - if (signature != null) { - assertThat(SigWriter.method(new SigParser(signature).parseMethodSig())) - .isEqualTo(signature); - totalSignatures[0]++; - } - return super.visitMethod(access, name, desc, signature, exceptions); - } - }, - ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG); + ClassFile classFile = ClassReader.read(path.toString(), Files.readAllBytes(path)); + { + String signature = classFile.signature(); + if (signature != null) { + assertThat(SigWriter.classSig(new SigParser(signature).parseClassSig())) + .isEqualTo(signature); + totalSignatures[0]++; + } + } + for (ClassFile.FieldInfo field : classFile.fields()) { + String signature = field.signature(); + if (signature != null) { + assertThat(SigWriter.type(new SigParser(signature).parseFieldSig())) + .isEqualTo(signature); + totalSignatures[0]++; + } + } + for (ClassFile.MethodInfo method : classFile.methods()) { + String signature = method.signature(); + if (signature != null) { + assertThat(SigWriter.method(new SigParser(signature).parseMethodSig())) + .isEqualTo(signature); + totalSignatures[0]++; + } + } } catch (IOException e) { throw new UncheckedIOException(e); }