diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-01-19 07:21:52 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-01-19 07:21:52 +0000 |
commit | ad7d5a92142d2e0e877f34495d2fb08357c9a9e9 (patch) | |
tree | ce05b26e23475f024e79747893fc2ab99c3f565b | |
parent | 3f6d86e0330351eb5d57b43cac3045f0e843b333 (diff) | |
download | javassist-ad7d5a92142d2e0e877f34495d2fb08357c9a9e9.tar.gz javassist-ad7d5a92142d2e0e877f34495d2fb08357c9a9e9.zip |
fixed a bug in getModifiers() in CtClass.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@236 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | src/main/javassist/CtClass.java | 3 | ||||
-rw-r--r-- | src/main/javassist/CtClassType.java | 10 | ||||
-rw-r--r-- | src/main/javassist/Modifier.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/ClassFile.java | 23 | ||||
-rw-r--r-- | src/main/javassist/util/proxy/ProxyFactory.java | 6 |
6 files changed, 45 insertions, 1 deletions
diff --git a/Readme.html b/Readme.html index 3d7f8d92..a7eaede9 100644 --- a/Readme.html +++ b/Readme.html @@ -289,6 +289,8 @@ see javassist.Dump. public members. <li>getEnclosingClass() in javassist.CtClass was renamed to getEnclosingMethod(). + <li>getModifiers() was extended to return Modifier.STATIC if the class + is a static inner class. <li>The return type of CtClass.stopPruning() was changed from void to boolean. <li>toMethod() in javassist.CtConstructor has been implemented. diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 7e23352c..31ea035c 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -437,6 +437,9 @@ public abstract class CtClass { * Returns the modifiers for this class, encoded in an integer. * For decoding, use <code>javassist.Modifier</code>. * + * <p>If the class is a static nested class (a.k.a. static inner class), + * the returned modifiers include <code>Modifier.STATIC</code>. + * * @see Modifier */ public int getModifiers() { diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 1eb9ba35..04500c2d 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -358,12 +358,20 @@ class CtClassType extends CtClass { } public int getModifiers() { - int acc = getClassFile2().getAccessFlags(); + ClassFile cf = getClassFile2(); + int acc = cf.getAccessFlags(); acc = AccessFlag.clear(acc, AccessFlag.SUPER); + int inner = cf.getInnerAccessFlags(); + if (inner != -1 && (inner & AccessFlag.STATIC) != 0) + acc |= AccessFlag.STATIC; + return AccessFlag.toModifier(acc); } public void setModifiers(int mod) { + if (Modifier.isStatic(mod)) + throw new RuntimeException("cannot set to static"); + checkModify(); int acc = AccessFlag.of(mod) | AccessFlag.SUPER; getClassFile2().setAccessFlags(acc); diff --git a/src/main/javassist/Modifier.java b/src/main/javassist/Modifier.java index d56969e8..7b3cfc79 100644 --- a/src/main/javassist/Modifier.java +++ b/src/main/javassist/Modifier.java @@ -40,6 +40,8 @@ public class Modifier { public static final int INTERFACE = AccessFlag.INTERFACE; public static final int ABSTRACT = AccessFlag.ABSTRACT; public static final int STRICT = AccessFlag.STRICT; + public static final int ANNOTATION = AccessFlag.ANNOTATION; + public static final int ENUM = AccessFlag.ENUM; /** * Returns true if the modifiers include the <tt>public</tt> diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 44f378e2..831a9608 100644 --- a/src/main/javassist/bytecode/ClassFile.java +++ b/src/main/javassist/bytecode/ClassFile.java @@ -234,6 +234,29 @@ public final class ClassFile { } /** + * Returns access and property flags of this nested class. + * This method returns -1 if the class is not a nested class. + * + * <p>The returned value is obtained from <code>inner_class_access_flags</code> + * of the entry representing this nested class itself + * in <code>InnerClasses_attribute</code>>. + */ + public int getInnerAccessFlags() { + InnerClassesAttribute ica + = (InnerClassesAttribute)getAttribute(InnerClassesAttribute.tag); + if (ica == null) + return -1; + + String name = getName(); + int n = ica.tableLength(); + for (int i = 0; i < n; ++i) + if (name.equals(ica.innerClass(i))) + return ica.accessFlags(i); + + return -1; + } + + /** * Returns the class name. */ public String getName() { diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index ecdd170f..55caa07c 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -50,6 +50,12 @@ import javassist.bytecode.*; * } * }; * f.setHandler(mi); + * f.setFilter(new MethodFilter() { + * public boolean isHandled(Method m) { + * // ignore finalize() + * return !m.getName().equals("finalize"); + * } + * }); * Class c = f.createClass(); * Foo foo = (Foo)c.newInstance(); * </pre></ul> |