Debian Codegraph @

asm-jdk-bridge-test/src/main/java/codes/rafael/asmjdkbridge/test/AsmTestAttribute.java

raw symbols SCIP
1 package codes.rafael.asmjdkbridge.test;
2
3 import org.objectweb.asm.Attribute;
4 import org.objectweb.asm.ByteVector;
5 import org.objectweb.asm.ClassReader;
6 import org.objectweb.asm.ClassWriter;
7 import org.objectweb.asm.Label;
8
9 public class AsmTestAttribute extends Attribute {
10
11 private final byte[] bytes;
12
13 public AsmTestAttribute() {
14 super("CustomAttribute");
15 bytes = null;
16 }
17
18 public AsmTestAttribute(byte[] bytes) {
19 super("CustomAttribute");
20 this.bytes = bytes;
21 }
22
23 @Override
24 @SuppressWarnings("deprecation")
25 protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
26 AsmTestAttribute attribute = new AsmTestAttribute(new byte[length]);
27 System.arraycopy(classReader.b, offset, attribute.bytes, 0, length);
28 return attribute;
29 }
30
31 @Override
32 protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
33 ByteVector vector = new ByteVector(bytes.length);
34 vector.putByteArray(bytes, 0, bytes.length);
35 return vector;
36 }
37
38 @Override
39 public boolean isUnknown() {
40 return false;
41 }
42
43 public static class AsmCodeTestAttribute extends Attribute {
44
45 private final byte[] bytes;
46
47 public AsmCodeTestAttribute() {
48 super("CustomCodeAttribute");
49 bytes = null;
50 }
51
52 public AsmCodeTestAttribute(byte[] bytes) {
53 super("CustomCodeAttribute");
54 this.bytes = bytes;
55 }
56
57 @Override
58 public boolean isCodeAttribute() {
59 return true;
60 }
61
62 @Override
63 @SuppressWarnings("deprecation")
64 protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
65 AsmCodeTestAttribute attribute = new AsmCodeTestAttribute(new byte[length]);
66 System.arraycopy(classReader.b, offset, attribute.bytes, 0, length);
67 return attribute;
68 }
69
70 @Override
71 protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
72 ByteVector vector = new ByteVector(bytes.length);
73 vector.putByteArray(bytes, 0, bytes.length);
74 return vector;
75 }
76 }
77 }