This repository was archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.java
49 lines (37 loc) · 1.93 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.github.seggan.javaclasslib.tests;
import io.github.seggan.javaclasslib.ClassAccessFlags;
import io.github.seggan.javaclasslib.JavaClass;
import io.github.seggan.javaclasslib.attributes.code.CodeAttribute;
import io.github.seggan.javaclasslib.attributes.code.ExceptionsAttribute;
import io.github.seggan.javaclasslib.attributes.code.instructions.JvmInstructions;
import io.github.seggan.javaclasslib.constantpool.ClassEntry;
import io.github.seggan.javaclasslib.constantpool.UTF8Entry;
import io.github.seggan.javaclasslib.methods.Method;
import io.github.seggan.javaclasslib.methods.MethodAccessFlags;
import io.github.seggan.javaclasslib.util.JCLUtils;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
JavaClass javaClass = new JavaClass("Testy", "java/lang/Object", 16);
javaClass.setClassAccessFlags(ClassAccessFlags.PUBLIC, ClassAccessFlags.FINAL);
Method main = new Method(new UTF8Entry(javaClass.getConstantPool(), "main"),
new UTF8Entry(javaClass.getConstantPool(), JCLUtils.generateMethodSignature(Void.class, String[].class)));
main.setAccessFlags(MethodAccessFlags.PUBLIC, MethodAccessFlags.STATIC);
CodeAttribute code = new CodeAttribute(new UTF8Entry(javaClass.getConstantPool(), "Code"),
2, 2,
JvmInstructions.ALOAD.create(0)
);
main.getAttributes().add(code);
ExceptionsAttribute exceptions = new ExceptionsAttribute(new UTF8Entry(javaClass.getConstantPool(), "Exceptions"),
new ClassEntry(javaClass.getConstantPool(), "java/io/IOException")
);
main.getAttributes().add(exceptions);
javaClass.getMethods().add(main);
try (FileOutputStream outputStream = new FileOutputStream("Testy.class")) {
javaClass.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
}