bytecode manipulation - Error generating java method using javaassist -
i having problem javaassist. i'm attempting generate class on fly , i'm getting error says:
no such class: foo
during compilation step in generatefoomethod
step below. can help me?
seek { final classpool pool = classpool.getdefault(); pool.importpackage("com.amir"); // <-- foo exists here final ctclass ctclass = pool.makeclass(classname); ctclass.addmethod(generatefoomethod(ctclass, methodname)); homecoming ctclass.toclass(); } grab (exception e) { e.printstacktrace(); throw new runtimeexception("compile failed"); } } private static ctmethod generatefoomethod(final ctclass declaringclass, final string methodname) throws cannotcompileexception { final stringbuilder sb = new stringbuilder(); sb.append("public static foo " +methodname+ "(foo foo) {"); sb.append(" homecoming foo"); sb.append("}"); homecoming ctmethod.make(sb.tostring(), declaringclass); // <-- failure happens here }
i've tried explicitly referring foo in method declaration in:
sb.append("public static com.amir.foo " +methodname+ "(com.amir.foo foo) {");
which not work.
java bytecode-manipulation javaassist
No comments:
Post a Comment