/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
/** * Makes a copy of this constructor and converts it into a method. * The signature of the mehtod is the same as the that of this constructor. * The return type is <code>void</code>. The resulting method must be * appended to the class specified by <code>declaring</code>. * If this constructor is a static initializer, the resulting method takes * no parameter. * * <p>An occurrence of another constructor call <code>this()</code> * or a super constructor call <code>super()</code> is * eliminated from the resulting method. * * <p>The immediate super class of the class declaring this constructor * must be also a super class of the class declaring the resulting method. * If the constructor accesses a field, the class declaring the resulting method * must also declare a field with the same name and type. * * @param name the name of the resulting method. * @param declaring the class declaring the resulting method. */ public CtMethod toMethod(String name, CtClass declaring) throws CannotCompileException { return toMethod(name, declaring, null); }
public static void disassemble(CtClass clazz, PrintStream out, boolean evenSuperclassMethods) { out.println("Class " + clazz.getName()); for (CtConstructor ctor : clazz.getConstructors()) try { disassemble(ctor.toMethod(ctor.getName(), clazz), out); } catch (CannotCompileException e) { e.printStackTrace(out); } for (CtMethod method : clazz.getDeclaredMethods()) if (evenSuperclassMethods || method.getDeclaringClass().equals(clazz)) disassemble(method, out); }
CtMethod defaultConstMethod = defaultCons.toMethod(DEFAULT_CONS_METHOD_NAME, classToModify); defaultConstMethod.setModifiers(Modifier.PUBLIC);
CtMethod defaultConstMethod = defaultCons.toMethod(DEFAULT_CONS_METHOD_NAME, classToModify); defaultConstMethod.setModifiers(Modifier.PUBLIC);