diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2009-04-04 15:41:55 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2009-04-04 15:41:55 +0000 |
commit | c4b9da1f23695844fc4535ad6b79c0eb59191ae1 (patch) | |
tree | f9b15b318d9a40505aa8ee22015b33849993a378 | |
parent | bead430f64ef930897dc4d25c36b854fec2d3092 (diff) | |
download | javassist-c4b9da1f23695844fc4535ad6b79c0eb59191ae1.tar.gz javassist-c4b9da1f23695844fc4535ad6b79c0eb59191ae1.zip |
for fixing JASSIST-68
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@474 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | Readme.html | 4 | ||||
-rw-r--r-- | src/main/javassist/ClassPool.java | 16 | ||||
-rw-r--r-- | src/main/javassist/CtNewClass.java | 20 |
3 files changed, 37 insertions, 3 deletions
diff --git a/Readme.html b/Readme.html index e7d90560..4435e7c2 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,7 @@ see javassist.Dump. <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 @@ -678,7 +678,7 @@ see javassist.Dump. <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> diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index f802ed6e..fd099794 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -724,6 +724,14 @@ public class ClassPool { * 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. */ @@ -736,6 +744,14 @@ public class ClassPool { * 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. diff --git a/src/main/javassist/CtNewClass.java b/src/main/javassist/CtNewClass.java index a95414af..2229d417 100644 --- a/src/main/javassist/CtNewClass.java +++ b/src/main/javassist/CtNewClass.java @@ -90,10 +90,12 @@ class CtNewClass extends CtClassType { 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; } @@ -104,4 +106,20 @@ class CtNewClass extends CtClassType { "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; + } } |