blob: 039d6c22e7e62576daf96a7cd4100b67ce573286 [file] [log] [blame]
Clément Bérac2278402024-12-03 10:53:52 +01001// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package twr.twraddsuppressed.asm;
6
7import org.objectweb.asm.AnnotationVisitor;
8import org.objectweb.asm.ClassWriter;
9import org.objectweb.asm.FieldVisitor;
10import org.objectweb.asm.Label;
11import org.objectweb.asm.MethodVisitor;
12import org.objectweb.asm.Opcodes;
13import org.objectweb.asm.RecordComponentVisitor;
14
15public class TestClass$MyClosableDump implements Opcodes {
16
17 public static byte[] dump() throws Exception {
18
19 ClassWriter classWriter = new ClassWriter(0);
20 FieldVisitor fieldVisitor;
21 RecordComponentVisitor recordComponentVisitor;
22 MethodVisitor methodVisitor;
23 AnnotationVisitor annotationVisitor0;
24
25 classWriter.visit(
26 V9,
27 ACC_PUBLIC | ACC_SUPER,
28 "twr/twraddsuppressed/TestClass$MyClosable",
29 null,
30 "java/lang/Object",
31 new String[] {"java/io/Closeable"});
32
33 classWriter.visitSource("TestClass.java", null);
34
35 classWriter.visitInnerClass(
36 "twr/twraddsuppressed/TestClass$MyClosable",
37 "twr/twraddsuppressed/TestClass",
38 "MyClosable",
39 ACC_PUBLIC | ACC_STATIC);
40
41 {
42 methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
43 methodVisitor.visitCode();
44 Label label0 = new Label();
45 methodVisitor.visitLabel(label0);
46 methodVisitor.visitLineNumber(10, label0);
47 methodVisitor.visitVarInsn(ALOAD, 0);
48 methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
49 methodVisitor.visitInsn(RETURN);
50 Label label1 = new Label();
51 methodVisitor.visitLabel(label1);
52 methodVisitor.visitLocalVariable(
53 "this", "Ltwraddsuppressed/TestClass$MyClosable;", null, label0, label1, 0);
54 methodVisitor.visitMaxs(1, 1);
55 methodVisitor.visitEnd();
56 }
57 {
58 methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "close", "()V", null, null);
59 methodVisitor.visitCode();
60 Label label0 = new Label();
61 methodVisitor.visitLabel(label0);
62 methodVisitor.visitLineNumber(14, label0);
63 methodVisitor.visitTypeInsn(NEW, "java/lang/RuntimeException");
64 methodVisitor.visitInsn(DUP);
65 methodVisitor.visitLdcInsn("CLOSE");
66 methodVisitor.visitMethodInsn(
67 INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false);
68 methodVisitor.visitInsn(ATHROW);
69 Label label1 = new Label();
70 methodVisitor.visitLabel(label1);
71 methodVisitor.visitLocalVariable(
72 "this", "Ltwraddsuppressed/TestClass$MyClosable;", null, label0, label1, 0);
73 methodVisitor.visitMaxs(3, 1);
74 methodVisitor.visitEnd();
75 }
76 classWriter.visitEnd();
77
78 return classWriter.toByteArray();
79 }
80}