You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Test.java 773B

1234567891011121314151617181920
  1. import javassist.*;
  2. public class Test {
  3. public static void main(String[] args) throws Exception {
  4. ClassPool cp = ClassPool.getDefault();
  5. CtClass newClass = cp.makeClass("test4.TestDeadcode");
  6. addDeadCode(newClass, "public void evaluate5(){ boolean b = !false; b = false && b; b = true && true;"
  7. + " b = true || b; b = b || false; }");
  8. newClass.debugWriteFile();
  9. Class<?> cClass = newClass.toClass();
  10. Object o = cClass.newInstance();
  11. java.lang.reflect.Method m = cClass.getMethod("evaluate5");
  12. m.invoke(o);
  13. }
  14. private static void addDeadCode(CtClass cc, String meth) throws Exception {
  15. CtMethod m = CtNewMethod.make(meth, cc);
  16. cc.addMethod(m);
  17. }
  18. }