diff options
Diffstat (limited to 'src/main/javassist')
-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 |
5 files changed, 43 insertions, 1 deletions
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> |