From c4b9da1f23695844fc4535ad6b79c0eb59191ae1 Mon Sep 17 00:00:00 2001 From: chiba Date: Sat, 4 Apr 2009 15:41:55 +0000 Subject: [PATCH] for fixing JASSIST-68 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@474 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- Readme.html | 4 ++-- src/main/javassist/ClassPool.java | 16 ++++++++++++++++ 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.

-version 3.11

-version 3.10 on March 5, 2009 @@ -678,7 +678,7 @@ see javassist.Dump.

  • Jar/zip files are supported. -

    -version 0.1 in April, 1999. +

    -version 0.1 on April 16, 1999.

    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. * + *

    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. * + *

    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; + } } -- 2.39.5