Esempio n. 1
0
  private static void replaceImplementation(CtMethod m, String src) throws Exception {
    removeNativeModifier(m);

    if (src == null || src.trim().length() == 0) {
      m.setBody(null);
    } else {
      src = src.trim();
      if (!src.startsWith("{")) {
        if (!m.getReturnType().equals(CtClass.voidType) && !src.startsWith("return")) {
          src = "{ return ($r)($w) " + src;
        } else {
          src = "{ " + src;
        }
      }

      if (!src.endsWith("}")) {
        if (!src.endsWith(";")) {
          src = src + "; }";
        } else {
          src = src + " }";
        }
      }
      try {
        m.setBody(src);
      } catch (CannotCompileException e) {
        throw new RuntimeException("Unable to compile body " + src, e);
      }
    }
  }
Esempio n. 2
0
 private static void insertAfter(CtMethod m, String newBody) throws Exception {
   removeNativeModifier(m);
   m.insertAfter(newBody);
 }