Package javassist

Examples of javassist.CtClass.addConstructor()


                                new Class[]{ Method[].class, Object.class, Interceptor.class } ),
                        proxyClass );
                proxyConstructor
                        .setBody(
                                "{\n\tthis.methods = $1;\n\tthis.target = $2;\n\tthis.interceptor = $3; }" );
                proxyClass.addConstructor( proxyConstructor );
                for( int i = 0; i < methods.length; ++i )
                {
                    final CtMethod method = new CtMethod( JavassistUtils.resolve( methods[i].getReturnType() ),
                                                          methods[i].getName(),
                                                          JavassistUtils.resolve( methods[i].getParameterTypes() ),
View Full Code Here


                JavassistUtils.addField( ObjectProvider.class, "provider", proxyClass );
                final CtConstructor proxyConstructor = new CtConstructor(
                        JavassistUtils.resolve( new Class[]{ ObjectProvider.class } ),
                        proxyClass );
                proxyConstructor.setBody( "{ this.provider = $1; }" );
                proxyClass.addConstructor( proxyConstructor );
                JavassistUtils.addInterfaces( proxyClass, toInterfaces( proxyClasses ) );
                final Method[] methods = getImplementationMethods( proxyClasses );
                for( int i = 0; i < methods.length; ++i )
                {
                    final Method method = methods[i];
View Full Code Here

                JavassistInvocation.class );
        final CtConstructor constructor = new CtConstructor(
                JavassistUtils.resolve( new Class[]{ Method.class, Object.class, Object[].class } ),
                ctClass );
        constructor.setBody( "{\n\tsuper($$);\n}" );
        ctClass.addConstructor( constructor );
        final CtMethod proceedMethod = new CtMethod( JavassistUtils.resolve( Object.class ), "proceed",
                                                     JavassistUtils.resolve( new Class[0] ), ctClass );
        final Class[] argumentTypes = interfaceMethod.getParameterTypes();
        final StringBuffer proceedBody = new StringBuffer( "{\n" );
        if( !Void.TYPE.equals( interfaceMethod.getReturnType() ) )
View Full Code Here

                        JavassistUtils.resolve(
                                new Class[]{ Method[].class, Invoker.class } ),
                        proxyClass );
                proxyConstructor
                        .setBody( "{\n\tthis.methods = $1;\n\tthis.invoker = $2; }" );
                proxyClass.addConstructor( proxyConstructor );
                for( int i = 0; i < methods.length; ++i )
                {
                    final CtMethod method = new CtMethod( JavassistUtils.resolve( methods[i].getReturnType() ),
                                                          methods[i].getName(),
                                                          JavassistUtils.resolve( methods[i].getParameterTypes() ),
View Full Code Here

        code.addRet(2);
        CodeAttribute ca = code.toCodeAttribute();
        mi.addAttribute(ca);
        mi.rebuildStackMap(loader);
        cf.addMethod(mi);
        cc.addConstructor(CtNewConstructor.make("public StackMapTestJsrTest() {}", cc));
        cc.addMethod(CtMethod.make("public static void main(String[] args) {"
                                 + "new javassist.bytecode.StackMapTestJsrTest().test();"
                                 + "}",
                                   cc));
        cc.writeFile();
View Full Code Here

            targetCt.setModifiers(Modifier.PUBLIC | Modifier.FINAL);

            CtConstructor constructorCt = new CtConstructor(null, targetCt);
            constructorCt.setModifiers(Modifier.PUBLIC);
            constructorCt.setBody("{ throw new RuntimeException(\"HikariCP Codahale shim says: Codahale metrics library is required but was not found in the classpath\"); }");
            targetCt.addConstructor(constructorCt);

            targetCt.toClass(classPool.getClassLoader(), getClass().getProtectionDomain());
         }
         catch (CannotCompileException cce) {
            LOGGER.error("Cannot generate CodaHale metrics shim", cce);
View Full Code Here

            } catch (ClassNotFoundException e) {
                ClassPool pool = ClassGenerator.getClassPool(clazz.getClassLoader());
                CtClass ctClass = pool.makeClass(parameterClassName);
                ClassFile classFile = ctClass.getClassFile();
                classFile.setVersionToJava5();
                ctClass.addConstructor(CtNewConstructor.defaultConstructor(pool.getCtClass(parameterClassName)));
                // parameter fields
                Class<?>[] parameterTypes = method.getParameterTypes();
                Annotation[][] parameterAnnotations = method.getParameterAnnotations();
                for (int i = 0; i < parameterTypes.length; i ++) {
                    Class<?> type = parameterTypes[i];
View Full Code Here

      CtClass clazz = pool.makeClass(fullName);

      // add a default constructor
      CtConstructor constructor = new CtConstructor(null, clazz);
      constructor.setBody("{super();}");
      clazz.addConstructor(constructor);

      // add the method implementation
      CtMethod m = CtNewMethod.make(methodDef, clazz);
      clazz.addMethod(m);
View Full Code Here

                    break;
                }
            }
            if (!hasDefaultConstructor && !ctClass.isInterface()) {
                CtConstructor defaultConstructor = CtNewConstructor.make("public " + ctClass.getSimpleName() + "() {}", ctClass);
                ctClass.addConstructor(defaultConstructor);
            }
        } catch (Exception e) {
            Logger.error(e, "Error in PropertiesEnhancer");
            throw new UnexpectedException("Error in PropertiesEnhancer", e);
        }
View Full Code Here

                    break;
                }
            }
            if (!hasDefaultConstructor) {
                CtConstructor defaultConstructor = CtNewConstructor.defaultConstructor(ctClass);
                ctClass.addConstructor(defaultConstructor);
            }
        } catch (Exception e) {
            Logger.error(e, "Error in PropertiesEnhancer");
            throw new UnexpectedException("Error in PropertiesEnhancer", e);
        }
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.