<p>-version 3.11
<ul>
- <li>JIRA JASSIST-74, 75, 76 were fixed.
+ <li>JIRA JASSIST-68, 74, 75, 76 were fixed.
</ul>
<p>-version 3.10 on March 5, 2009
<li>Jar/zip files are supported.
</ul>
-<p>-version 0.1 in April, 1999.
+<p>-version 0.1 on April 16, 1999.
<ul>
<li>The first release.
</ul>
* If there already exists a class with the same name, the new class
* overwrites that previous class.
*
+ * <p>If no constructor is explicitly added to the created new
+ * class, Javassist generates constructors and adds it when
+ * the class file is generated. It generates a new constructor
+ * for each constructor of the super class. The new constructor
+ * takes the same set of parameters and invokes the
+ * corresponding constructor of the super class. All the received
+ * parameters are passed to it.
+ *
* @param classname a fully-qualified class name.
* @throws RuntimeException if the existing class is frozen.
*/
* If there already exists a class/interface with the same name,
* the new class overwrites that previous class.
*
+ * <p>If no constructor is explicitly added to the created new
+ * class, Javassist generates constructors and adds it when
+ * the class file is generated. It generates a new constructor
+ * for each constructor of the super class. The new constructor
+ * takes the same set of parameters and invokes the
+ * corresponding constructor of the super class. All the received
+ * parameters are passed to it.
+ *
* @param classname a fully-qualified class name.
* @param superclass the super class.
* @throws RuntimeException if the existing class is frozen.
int n = 0;
for (int i = 0; i < cs.length; ++i) {
CtConstructor c = cs[i];
- if (Modifier.isPublic(c.getModifiers())) {
+ int mod = c.getModifiers();
+ if (isInheritable(mod, superclazz)) {
CtConstructor cons
= CtNewConstructor.make(c.getParameterTypes(),
c.getExceptionTypes(), this);
+ cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE));
addConstructor(cons);
++n;
}
"no public constructor in " + superclazz.getName());
}
+
+ private boolean isInheritable(int mod, CtClass superclazz) {
+ if (Modifier.isPrivate(mod))
+ return false;
+
+ if (Modifier.isPackage(mod)) {
+ String pname = getPackageName();
+ String pname2 = superclazz.getPackageName();
+ if (pname == null)
+ return pname2 == null;
+ else
+ pname.equals(pname2);
+ }
+
+ return true;
+ }
}