Package javassist

Examples of javassist.CtClass.detach()


   
    ClassPool pool = ClassPool.getDefault();
    // Class have to have no package name for the JPQL to work, not clear why, presumably I missed a mapping somewhere
    // but it doesn't matter because this class is internal to the process space anyway
    CtClass cc = pool.makeClass("TemplateClass" + nStep);
    cc.detach();
    // Remove all fields:
    for (CtField toRemove: cc.getFields()) {
      cc.removeField(toRemove);
    }
   
View Full Code Here


        for (CtMethod m : cc.getDeclaredMethods()) {
          m.insertBefore("org.stagemonitor.requestmonitor.profiler.Profiler.start();");
          m.insertAfter("org.stagemonitor.requestmonitor.profiler.Profiler.stop(\""+m.getLongName()+"\");", true);
        }
        byteCode = cc.toBytecode();
        cc.detach();
      } catch (Exception ex) {
        throw new RuntimeException(ex);
      }
    }
View Full Code Here

            CtClass c = classPool.getAndRename(NoOpTypeParameterMatcher.class.getName(), className);
            c.setModifiers(c.getModifiers() | Modifier.FINAL);
            c.getDeclaredMethod("match").setBody("{ return $1 instanceof " + typeName + "; }");
            byte[] byteCode = c.toBytecode();
            c.detach();
            Method method = ClassLoader.class.getDeclaredMethod(
                    "defineClass", String.class, byte[].class, int.class, int.class);
            method.setAccessible(true);

            Class<?> generated = (Class<?>) method.invoke(classLoader, className, byteCode, 0, byteCode.length);
View Full Code Here

         {
            handleCtClass(ctClass, resource);
         }
         finally
         {
            ctClass.detach();              
         }
      }
      catch (ClassNotFoundException e)
      {
         if (forceAnnotations)
View Full Code Here

        if (cc == null) {
            return null;
        }
        byte[] newClass = cc.toBytecode();
        cc.defrost();
        cc.detach();
        return newClass;
    }

    /**
     * Try to perform the actual model enhancing.
View Full Code Here

  public void removeGeneratedClasses() {
    ClassPool pool = ClassPool.getDefault();
    for (Class<?> clazz : interfaces.values()) {
      CtClass ctClass = pool.getOrNull(clazz.getName());
      if (ctClass != null) {
        ctClass.detach();
        logger.debug("class {} is detached", clazz.getName());
      }
    }
  }
}
View Full Code Here

         {
            handleCtClass(ctClass, resource);
         }
         finally
         {
            ctClass.detach();              
         }
      }
      catch (ClassNotFoundException e)
      {
         if (forceAnnotations)
View Full Code Here

      Enum[] enums = c.getEnumConstants();

      // Rewrite the enum class
      CtClass oldEnum = info.getClazz();
      ClassPool pool = oldEnum.getClassPool();
      oldEnum.detach();
      CtClass baseEnum = pool.get("org.jboss.lang.Enum");
      CtClass newEnum = pool.makeClass(classname, baseEnum);

      // Create the enum ctor
      String ctorSrc = "protected " + newEnum.getSimpleName() + "(String name, int ord){super(name, ord);}";
View Full Code Here

            if (verbose) {
                e.printStackTrace();
            }
        } finally {
            if (cl != null) {
                cl.detach();
            }
        }
        return classBytes;
    }
View Full Code Here

  public void removeGeneratedClasses() {
    ClassPool pool = ClassPool.getDefault();
    for (Class<?> clazz : interfaces.values()) {
      CtClass ctClass = pool.getOrNull(clazz.getName());
      if (ctClass != null) {
        ctClass.detach();
        logger.debug("class {} is detached", clazz.getName());
      }
    }
  }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.