package org.javalaunchpad;

import java.io.IOException;
import java.lang.classfile.*;
import java.lang.classfile.attribute.StackMapFrameInfo;
import java.lang.classfile.attribute.StackMapTableAttribute;
import java.nio.file.Path;
import java.util.List;

public class StackMapFrameTest {
    public static void main(String[] args) throws IOException {
        ClassModel classModel = ClassFile.of().parse(Path.of("Path to the class file"));
        classModel.elementList().forEach(element -> {
            if (element instanceof MethodModel mm && (mm.methodName().stringValue().equals("run"))) {
                for (MethodElement me : mm){
                    if (me instanceof CodeModel cm) {
                        for (Attribute<?> s : cm.attributes()) {
                            if (s instanceof StackMapTableAttribute smt) {
                                List<StackMapFrameInfo> entries = smt.entries();
                                for (StackMapFrameInfo entry : entries) {
                                    List<StackMapFrameInfo.VerificationTypeInfo> locals = entry.locals();
                                    List<StackMapFrameInfo.VerificationTypeInfo> stack = entry.stack();
                                    System.out.println(locals.size());
                                    System.out.println(stack.size());
                                }
                            }
                        }
                    }
                }
            }
        });
    }
}
