Package javassist

Examples of javassist.ClassPool.makeClass()


  public <T> Class enhanceResource(Class<T> originalType) {
    ClassPool pool = ClassPool.getDefault();
    try {
      // TODO extract this enhancement to an interface and test it appart
      CtClass newType =   pool.makeClass("br.com.caelum.restfulie." + originalType.getSimpleName() + "_" + System.currentTimeMillis());
      newType.setSuperclass(pool.get(originalType.getName()));
      newType.addInterface(pool.get(Resource.class.getName()));
//      enhanceMustIgnore(newType);
      enhanceLinks(newType);
      return newType.toClass();
View Full Code Here


       
        // first we need to load the class via javassist
        CtClass origClass = pool.get(cls.getName());
       
        // we create a new subclass with a certain postfix
        CtClass subClass = pool.makeClass(cls.getName() + "_intcpted", origClass);
       
        overrideInterceptedMethods(subClass);
       
        // now let's get the real class from it
        @SuppressWarnings("unchecked")
View Full Code Here

     * Protected for test only
     */
    protected static Class generate(String className, Map<String, Class<?>> properties) {
        try {
            ClassPool pool = ClassPool.getDefault();
            CtClass cc = pool.makeClass(className);

            cc.addInterface(resolveCtClass(Serializable.class));
            cc.addField(new CtField(resolveCtClass(Map.class), "theMap", cc));
            cc.addConstructor(generateConstructor(className, cc));

View Full Code Here

        final ClassLoader previous = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(loader);
        try {
            ClassPool pool = new ClassPool();
            pool.appendClassPath(new LoaderClassPath(loader));
            CtClass clazz = pool.makeClass(new ByteArrayInputStream(classfileBuffer));
            if (isAlreadyTransformed(clazz) == false) {
                log.info("Transforming " + className + " with " + getClass().getSimpleName());
                transform(clazz);
            } else {
                log.fine(className + " is already transformed with " + getClass().getSimpleName());
View Full Code Here

     * Revisit this after javassist support java 8
     */
    @SuppressWarnings({ "unchecked" })
    private <E extends Serializable> CopyExtractor<E> getExtractor(Class<E> clz, List<Method> fieldMethods) {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.makeClass("com.eclecticlogic.pedal.dialect.postgresql." + clz.getSimpleName()
                + "$CopyExtractor");

        StringBuilder methodBody = new StringBuilder();
        try {
            cc.addInterface(pool.getCtClass(CopyExtractor.class.getName()));
View Full Code Here

     */
    public ClassCustomizer(Class<?> iface, String oldlassName, String newClassName) {

        try {
            ClassPool pool = ClassPool.getDefault();
            ctClass = pool.makeClass(newClassName);
            classFile = ctClass.getClassFile();
            classFile.setSuperclass(oldlassName);

            classFile.setName(newClassName);

View Full Code Here

//    long start = System.currentTimeMillis();
    ClassPool classPool = ClassPool.getDefault();
    classPool.insertClassPath(new ClassClassPath(MethodProxy.class));
    classPool.importPackage(Method.class.getCanonicalName());
   
    CtClass cc = classPool.makeClass("com.firefly.utils.ProxyMethod" + UUID.randomUUID().toString().replace("-", ""));
   
    cc.addInterface(classPool.get(MethodProxy.class.getName()));
    cc.addField(CtField.make("private Method method;", cc));
   
    CtConstructor constructor = new CtConstructor(new CtClass[]{classPool.get(Method.class.getName())}, cc);
View Full Code Here

//    long start = System.currentTimeMillis();
    ClassPool classPool = ClassPool.getDefault();
    classPool.insertClassPath(new ClassClassPath(FieldProxy.class));
    classPool.importPackage(Field.class.getCanonicalName());
   
    CtClass cc = classPool.makeClass("com.firefly.utils.ProxyField" + UUID.randomUUID().toString().replace("-", ""));
    cc.addInterface(classPool.get(FieldProxy.class.getName()));
    cc.addField(CtField.make("private Field field;", cc));
   
    CtConstructor constructor = new CtConstructor(new CtClass[]{classPool.get(Field.class.getName())}, cc);
    constructor.setBody("{this.field = (Field)$1;}");
View Full Code Here

  private ArrayProxy _getArrayProxy(Class<?> clazz) throws Throwable {
//    long start = System.currentTimeMillis();
    ClassPool classPool = ClassPool.getDefault();
    classPool.insertClassPath(new ClassClassPath(ArrayProxy.class));
   
    CtClass cc = classPool.makeClass("com.firefly.utils.ArrayField" + UUID.randomUUID().toString().replace("-", ""));
    cc.addInterface(classPool.get(ArrayProxy.class.getName()));
   
    cc.addMethod(CtMethod.make(createArraySizeCode(clazz), cc));
    cc.addMethod(CtMethod.make(createArrayGetCode(clazz), cc));
    cc.addMethod(CtMethod.make(createArraySetCode(clazz), cc));
View Full Code Here

public class ClassGenerationUtil {

    private static byte[] makeClass( final String name, final String... fields ) {
        final ClassPool pool = ClassPool.getDefault();

        final CtClass newClass = pool.makeClass( name );

        try {
            for ( final String field : fields ) {
                newClass.addField( new CtField( pool.get( "java.lang.String"), field, newClass ) );
            }
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.