/** * Creates a public constructor that only calls a constructor * in the super class. The created constructor receives parameters * specified by <code>parameters</code> and calls the super's * constructor with those parameters. * * @param parameters parameter types * @param exceptions exception types * @param declaring the class to which the created constructor * is added. */ public static CtConstructor make(CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws CannotCompileException { return make(parameters, exceptions, PASS_PARAMS, null, null, declaring); }
/** * Creates a public constructor that only calls a constructor * in the super class. The created constructor receives parameters * specified by <code>parameters</code> but calls the super's * constructor without those parameters (that is, it calls the default * constructor). * * <p>The parameters passed to the created constructor should be * used for field initialization. <code>CtField.Initializer</code> * objects implicitly insert initialization code in constructor * bodies. * * @param parameters parameter types * @param exceptions exception types * @param declaring the class to which the created constructor * is added. * @see CtField.Initializer#byParameter(int) */ public static CtConstructor skeleton(CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws CannotCompileException { return make(parameters, exceptions, PASS_NONE, null, null, declaring); }
/** * Creates a public constructor that only calls a constructor * in the super class. The created constructor receives parameters * specified by <code>parameters</code> and calls the super's * constructor with those parameters. * * @param parameters parameter types * @param exceptions exception types * @param declaring the class to which the created constructor * is added. */ public static CtConstructor make(CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws CannotCompileException { return make(parameters, exceptions, PASS_PARAMS, null, null, declaring); }
/** * Creates a public constructor that only calls a constructor * in the super class. The created constructor receives parameters * specified by <code>parameters</code> but calls the super's * constructor without those parameters (that is, it calls the default * constructor). * * <p>The parameters passed to the created constructor should be * used for field initialization. <code>CtField.Initializer</code> * objects implicitly insert initialization code in constructor * bodies. * * @param parameters parameter types * @param exceptions exception types * @param declaring the class to which the created constructor * is added. * @see CtField.Initializer#byParameter(int) */ public static CtConstructor skeleton(CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws CannotCompileException { return make(parameters, exceptions, PASS_NONE, null, null, declaring); }
public static CtClass addPatchConstruct(CtClass patchClass, CtClass sourceClass) { try { CtField originField = new CtField(sourceClass, ORIGINCLASS, patchClass); patchClass.addField(originField); StringBuilder patchClassConstruct = new StringBuilder(); patchClassConstruct.append(" public Patch(Object o) {"); patchClassConstruct.append(ORIGINCLASS + "=(" + sourceClass.getName() + ")o;"); patchClassConstruct.append("}"); CtConstructor constructor = CtNewConstructor.make(patchClassConstruct.toString(), patchClass); patchClass.addConstructor(constructor); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } return patchClass; }
public Proxy<I> addConstructor(String code) { return handleException(() -> ctClass.addConstructor(CtNewConstructor.make(code, ctClass))); }
if (method.length() > 0) { if (method.startsWith(className)) { cls.addConstructor(CtNewConstructor.make("public " + method, cls)); } else if (FIELD_PATTERN.matcher(method).matches()) { cls.addField(CtField.make("private " + method, cls));
if (method.length() > 0) { if (method.startsWith(className)) { cls.addConstructor(CtNewConstructor.make("public " + method, cls)); } else if (FIELD_PATTERN.matcher(method).matches()) { cls.addField(CtField.make("private " + method, cls));
String[] sn = mCtc.getSimpleName().split("\\$+"); // inner class name include $. mCtc.addConstructor( CtNewConstructor.make(code.replaceFirst(SIMPLE_NAME_TAG, sn[sn.length - 1]), mCtc));
String[] sn = mCtc.getSimpleName().split("\\$+"); // inner class name include $. mCtc.addConstructor( CtNewConstructor.make(code.replaceFirst(SIMPLE_NAME_TAG, sn[sn.length - 1]), mCtc));
if (method.length() > 0) { if (method.startsWith(className)) { cls.addConstructor(CtNewConstructor.make("public " + method, cls)); } else if (FIELD_PATTERN.matcher(method).matches()) { cls.addField(CtField.make("private " + method, cls));
if (method.length() > 0) { if (method.startsWith(className)) { cls.addConstructor(CtNewConstructor.make("public " + method, cls)); } else if (FIELD_PATTERN.matcher(method).matches()) { cls.addField(CtField.make("private " + method, cls));
CtConstructor happyConst = CtNewConstructor.make(cons,scClass); scClass.addConstructor(happyConst);
cc.setSuperclass(baseStateClass); final CtConstructor cons = CtNewConstructor.make(null, new CtClass[0], cc); cc.addConstructor(cons);
cc.setSuperclass(ccActorReference); cc.addInterface(ccInterface); cc.addConstructor(CtNewConstructor.make(new CtClass[]{ pool.get(String.class.getName()) }, null, "{ super($1); }", cc));
if (isInheritable(mod, superclazz)) { CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE));
} else { String[] sn = mCtc.getSimpleName().split("\\$+"); // inner class name include $. mCtc.addConstructor(CtNewConstructor.make(code.replaceFirst(SIMPLE_NAME_TAG, sn[sn.length - 1]), mCtc));
private void ensureNullaryCtor(CtClass cc) throws NotFoundException, CannotCompileException { // Build a null-ary constructor if needed String clzname = cc.getSimpleName(); if( !hasExisting(clzname,"()V",cc.getDeclaredConstructors()) ) { String body = "public "+clzname+"() { }"; cc.addConstructor(CtNewConstructor.make(body,cc)); } else { CtConstructor ctor = cc.getConstructor("()V"); ctor.setModifiers(javassist.Modifier.setPublic(ctor.getModifiers())); } }
if (isInheritable(mod, superclazz)) { CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE));
protected void buildConstructor() throws CannotCompileException, NotFoundException { // Constructor(Class targetClass, Template[] templates) CtConstructor newCtCons = CtNewConstructor.make( new CtClass[] { director.getCtClass(Class.class.getName()), director.getCtClass(Template.class.getName() + "[]") }, new CtClass[0], tmplCtClass); tmplCtClass.addConstructor(newCtCons); }