mi1.setAccessFlags(AccessFlags.ACC_PUBLIC);
mi1.setNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf, "<init>", 0));
mi1.setDescriptorIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
"()V",
0));
CodeAttribute ca1 = new CodeAttribute();
ca1.setAttributeNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
CodeAttribute.ATTRIBUTE_NAME,
0));
ca1.setCode(ByteCodeWriter.writeByteCode(Arrays.asList(new org.gjt.jclasslib.bytecode.AbstractInstruction[] {
new SimpleInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_ALOAD_0),
new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_INVOKESPECIAL,
ConstantPoolUtil.addConstantMethodrefInfo(cf,
"java/lang/Object",
"<init>",
"()V",
0)),
new SimpleInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_RETURN) })));
ca1.setMaxStack(1);
ca1.setMaxLocals(1);
mi1.setAttributes(new AttributeInfo[] { ca1 });
ConstantStringInfo s = new ConstantStringInfo();
s.setStringIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
"Hello world!",
0));
org.gjt.jclasslib.structures.MethodInfo mi2 = new org.gjt.jclasslib.structures.MethodInfo();
mi2.setAccessFlags(AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC);
mi2.setNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf, "main", 0));
mi2.setDescriptorIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
"([Ljava/lang/String;)V",
0));
CodeAttribute ca2 = new CodeAttribute();
ca2.setAttributeNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
CodeAttribute.ATTRIBUTE_NAME,
0));
ca2.setCode(ByteCodeWriter.writeByteCode(Arrays.asList(new org.gjt.jclasslib.bytecode.AbstractInstruction[] {
new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_GETSTATIC,
ConstantPoolUtil.addConstantFieldrefInfo(cf,
"java/lang/System",
"out",
"Ljava/io/PrintStream;",
0)),
new ImmediateByteInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_LDC,
false,
ConstantPoolUtil.addConstantPoolEntry(cf, s, 0)),
new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_INVOKEVIRTUAL,
ConstantPoolUtil.addConstantMethodrefInfo(cf,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V",
0)) })));
ca2.setMaxStack(2);
ca2.setMaxLocals(1);
mi2.setAttributes(new AttributeInfo[] { ca2 });
cf.setMethods(new org.gjt.jclasslib.structures.MethodInfo[] { mi1, mi2 });
cf.setAttributes(new AttributeInfo[] { sa });