Package javassist

Examples of javassist.CtClass.addMethod()


            }
            methodBody.append("return builder.toString();\n");
            methodBody.append("} catch (Exception e) { throw new RuntimeException(e); } \n");
            methodBody.append("}\n");
            logger.trace(methodBody.toString());
            cc.addMethod(CtNewMethod.make(methodBody.toString(), cc));
        } catch (NotFoundException | CannotCompileException e) {
            logger.error(e.getMessage(), "Compiled body is:\n" + methodBody.toString());
            throw Throwables.propagate(e);
        }
View Full Code Here


            }
            methodBody.append("return builder.toString();\n");
            methodBody.append("} catch (Exception e) { throw new RuntimeException(e); } \n");
            methodBody.append("}\n");
            logger.trace(methodBody.toString());
            cc.addMethod(CtNewMethod.make(methodBody.toString(), cc));
        } catch (NotFoundException | CannotCompileException e) {
            logger.error(e.getMessage(), "Compiled body is:\n" + methodBody.toString());
            throw Throwables.propagate(e);
        }
View Full Code Here

            }
            methodBody.append("return builder.toString();\n");
            methodBody.append("} catch (Exception e) { throw new RuntimeException(e); } \n");
            methodBody.append("}\n");
            logger.trace(methodBody.toString());
            cc.addMethod(CtNewMethod.make(methodBody.toString(), cc));
        } catch (NotFoundException | CannotCompileException e) {
            logger.error(e.getMessage(), "Compiled body is:\n" + methodBody.toString());
            throw Throwables.propagate(e);
        }
View Full Code Here

                    final Class invocationClass = JavassistInvocation
                            .getMethodInvocationClass( classLoader, methods[i] );
                    final String body = "{\n\t return ( $r ) interceptor.intercept( new " + invocationClass.getName() +
                                        "( methods[" + i + "], target, $args ) );\n }";
                    method.setBody( body );
                    proxyClass.addMethod( method );

                }
                return proxyClass.toClass( classLoader );
            }
            catch( CannotCompileException e )
View Full Code Here

                                                            proxyClass );
                    final String body = "{ return ( $r ) ( ( " + method.getDeclaringClass().getName() +
                                        " )provider.getObject() )." +
                                        method.getName() + "($$); }";
                    ctMethod.setBody( body );
                    proxyClass.addMethod( ctMethod );

                }
                return proxyClass.toClass( classLoader );
            }
            catch( CannotCompileException e )
View Full Code Here

            proceedBody.append( "\treturn null;\n" );
        }
        proceedBody.append( "}" );
        final String body = proceedBody.toString();
        proceedMethod.setBody( body );
        ctClass.addMethod( proceedMethod );
        invocationClass = ctClass.toClass( classLoader );
        return invocationClass;
    }

    private static Map getClassCache( ClassLoader classLoader )
View Full Code Here

                                                          JavassistUtils.resolve( methods[i].getParameterTypes() ),
                                                          proxyClass );
                    final String body = "{\n\t return ( $r ) invoker.invoke( this, methods[" + i +
                                        "], $args );\n }";
                    method.setBody( body );
                    proxyClass.addMethod( method );
                }
                return proxyClass.toClass( classLoader );
            }
            catch( CannotCompileException e )
            {
View Full Code Here

        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();
        Object t1 = make(cc.getName());
View Full Code Here

      default:
        throw new CannotCompileException("");
      }
     
      CtMethod m = CtNewMethod.make(modifiers, returnType, mname, parameters, exceptions, body, declaring);
      declaring.addMethod(m);

    } catch (Exception e) {
      throw new CannotCompileException(e);
    }
   
View Full Code Here

         for (WrappedParameter param : wrappedParameters)
         {
            CtField field = new CtField(pool.get(param.getType()), param.getVariable(), clazz);
            field.setModifiers(Modifier.PRIVATE);
            clazz.addField(field);
            clazz.addMethod(CtNewMethod.getter("get" + JavaUtils.capitalize(param.getVariable()), field));
            clazz.addMethod(CtNewMethod.setter("set" + JavaUtils.capitalize(param.getVariable()), field));
         }

         wrapperType = (Class)pool.toClass(clazz, loader);
      }
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.