From: chiba Date: Thu, 19 Jan 2006 07:21:52 +0000 (+0000) Subject: fixed a bug in getModifiers() in CtClass. X-Git-Tag: rel_3_17_1_ga~391 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ad7d5a92142d2e0e877f34495d2fb08357c9a9e9;p=javassist.git fixed a bug in getModifiers() in CtClass. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@236 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- 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.
  • getEnclosingClass() in javassist.CtClass was renamed to getEnclosingMethod(). +
  • getModifiers() was extended to return Modifier.STATIC if the class + is a static inner class.
  • The return type of CtClass.stopPruning() was changed from void to boolean.
  • 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 javassist.Modifier. * + *

    If the class is a static nested class (a.k.a. static inner class), + * the returned modifiers include Modifier.STATIC. + * * @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 public 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 @@ -233,6 +233,29 @@ public final class ClassFile { accessFlags = acc | AccessFlag.SUPER; } + /** + * Returns access and property flags of this nested class. + * This method returns -1 if the class is not a nested class. + * + *

    The returned value is obtained from inner_class_access_flags + * of the entry representing this nested class itself + * in InnerClasses_attribute>. + */ + 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. */ 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(); *