Skip to content

Commit

Permalink
Use turbine's own class file parser in a test
Browse files Browse the repository at this point in the history
To fix a test failure on JDK 22, which ASM doesn't support yet.

PiperOrigin-RevId: 565964627
  • Loading branch information
cushon authored and Javac Team committed Sep 16, 2023
1 parent 4854e4e commit 0916053
Showing 1 changed file with 27 additions and 50 deletions.
77 changes: 27 additions & 50 deletions javatests/com/google/turbine/bytecode/sig/SigIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0916053

Please sign in to comment.