1 package samples.reflect.hello1; 2 3 import java.io.FileOutputStream ; 4 import java.lang.reflect.Modifier ; 5 6 import alt.jiapi.reflect.Instruction; 7 import alt.jiapi.reflect.InstructionFactory; 8 import alt.jiapi.reflect.InstructionList; 9 import alt.jiapi.reflect.JiapiClass; 10 import alt.jiapi.reflect.JiapiMethod; 11 import alt.jiapi.reflect.Loader; 12 import alt.jiapi.reflect.Signature; 13 14 public class HelloWorldBuilder { 15 public static void main(String args[]) throws Exception { 16 new HelloWorldBuilder(); 17 } 18 19 public HelloWorldBuilder() throws Exception { 20 Loader loader = new Loader(); 22 JiapiClass clazz = loader.loadClass("samples.reflect.hello1.Test"); 23 System.out.println(clazz); 24 25 Signature signature = new Signature("void", new String [] {} ); 29 JiapiMethod method = clazz.addMethod(Modifier.PUBLIC, "helloWorld", 30 signature); 31 32 InstructionList il = method.getInstructionList(); 35 InstructionFactory iFactory = method.getInstructionFactory(); 36 37 JiapiMethod println = clazz.getDeclaredMethod("println", new String [] 38 {"java.lang.Object"}); 39 40 43 il.add(iFactory.pushConstant("hello world!")); 44 45 il.add(iFactory.invoke(println)); 46 il.add(iFactory.returnMethod(method)); 47 48 50 clazz.dump(new FileOutputStream ("Test.class")); 51 } 52 } 53 | Popular Tags |