Package javassist

Examples of javassist.CtClass.addMethod()


                context.markAsPrepared();
                context.markAsAdvised();

                // add the wrapper methods
                for (Iterator it2 = wrapperMethods.iterator(); it2.hasNext();) {
                    ctClass.addMethod((CtMethod)it2.next());
                }
            }
        }
    }
View Full Code Here


            }
            methodBody.append("return builder.toString();\n");
            methodBody.append("} catch (Exception e) { throw new RuntimeException(e); } \n");
            methodBody.append("}\n");
            System.out.println(methodBody);
            cc.addMethod(CtNewMethod.make(methodBody.toString(), cc));
        } catch (NotFoundException | CannotCompileException e) {
            throw Throwables.propagate(e);
        }

        try {
View Full Code Here

        if (isClassAdvised) {
            context.markAsAdvised();

            // add the wrapper methods
            for (Iterator it2 = wrapperMethods.iterator(); it2.hasNext();) {
                ctClass.addMethod((CtMethod) it2.next());
            }
        }

        // handles pointcut unweaving
        // looping on the original methods is enough since we will look for
View Full Code Here

            if (isClassAdvised) {
                context.markAsAdvised();

                // add the wrapper methods
                for (Iterator it2 = wrapperMethods.iterator(); it2.hasNext();) {
                    ctClass.addMethod((CtMethod) it2.next());
                }
            }
        }
    }
View Full Code Here

    public void testSerialVerUidSynthetic() throws Throwable {
        CtClass javassistClass = ClassPool.getDefault().get(this.getClass().getName());
        // build a class with synthetic method, field, ctor
        javassistClass.setName(this.getClass().getName()+"Generated");
        int syntheticModifier = Constants.ACC_SYNTHETIC | Modifier.PUBLIC;
        javassistClass.addMethod(CtNewMethod.make(syntheticModifier, CtClass.intType, "syntheticDo", new CtClass[]{}, new CtClass[]{}, "{return 0;}", javassistClass));
        CtField field = new CtField(CtClass.intType, "syntheticField", javassistClass);
        field.setModifiers(syntheticModifier);
        javassistClass.addField(field);
        CtConstructor ctor = new CtConstructor(new CtClass[]{CtClass.intType}, javassistClass);
        ctor.setModifiers(syntheticModifier);
View Full Code Here

        CtMethod method = new CtMethod(pool.get("int"), "getNumber", null, ctClass);

        method.setBody("return " + number + ";");

        ctClass.addMethod(method);

        ctClass.writeFile(classesDir.getAbsolutePath());
    }

    /**
 
View Full Code Here

        ctClass.setSuperclass(pool.get(BasicComponent.class.getName()));

        // Implement method getName()

        CtMethod method = CtNewMethod.make("public String getName() { return \"" + name + "\"; }", ctClass);
        ctClass.addMethod(method);

        ctClass.addInterface(pool.get(Named.class.getName()));

        ctClass.writeFile(extraClasspath.getAbsolutePath());
    }
View Full Code Here

        CtMethod method = new CtMethod(pool.get("java.lang.String"), "getStatus", null, ctClass);

        method.setBody(String.format("return \"%s\";", status));

        ctClass.addMethod(method);

        ctClass.writeFile(classesDir.getAbsolutePath());
    }

    private void createInvalidImplentationClass() throws Exception
View Full Code Here

        // Implement method getName()

        CtMethod method = CtNewMethod.make(
                "public String getName() { return \"" + name + "\"; }",
                ctClass);
        ctClass.addMethod(method);

        ctClass.addInterface(pool.get(Named.class.getName()));

        ctClass.writeFile(_extraClasspath.getAbsolutePath());
    }
View Full Code Here

                impl.addField(patternField, CtField.Initializer.constant(value));
                CtField formatField = new CtField(messageFormat, method.getName()+"MessageFormat", impl);
                impl.addField(formatField, CtField.Initializer.byExpr("new java.text.MessageFormat("+patternField.getName()+", _locale)"));
                methodImpl.setModifiers(Modifier.PUBLIC);
                methodImpl.setBody("return "+formatField.getName()+".format($args, new StringBuffer(), null).toString();");
                impl.addMethod(methodImpl);
                keys.put(methodKey, defaultValue);
            }
            final Class implClazz = impl.toClass();
            final Constructor ctor = implClazz.getConstructor(Locale.class);
            Object instance = ctor.newInstance(locale);
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.