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.
* 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() {
}
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);
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>
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.
+ *
+ * <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.
*/
* }
* };
* 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>