summaryrefslogtreecommitdiffstats
path: root/src/main/javassist/CtNewNestedClass.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2005-09-15 09:40:34 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2005-09-15 09:40:34 +0000
commit3ab8846e75afa5c249f14005324113dfb33a0124 (patch)
tree1989020f2ebe9c75ce9fc9a384df6a2574ac39bc /src/main/javassist/CtNewNestedClass.java
parent14a5ac37971939f4cf9098bd86d6dd1ef6beaad3 (diff)
downloadjavassist-3ab8846e75afa5c249f14005324113dfb33a0124.tar.gz
javassist-3ab8846e75afa5c249f14005324113dfb33a0124.zip
renamed getEnclosingClass() in CtClass to getEnclosingMethod() and fixed a bug so that getModifiers() can work on an nested class.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@210 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/CtNewNestedClass.java')
-rw-r--r--src/main/javassist/CtNewNestedClass.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main/javassist/CtNewNestedClass.java b/src/main/javassist/CtNewNestedClass.java
index fd02130e..cd91c569 100644
--- a/src/main/javassist/CtNewNestedClass.java
+++ b/src/main/javassist/CtNewNestedClass.java
@@ -15,8 +15,12 @@
package javassist;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.AccessFlag;
+import javassist.bytecode.InnerClassesAttribute;
+
/**
- * A newly created nested class.
+ * A newly created public nested class.
*/
class CtNewNestedClass extends CtNewClass {
CtNewNestedClass(String realName, ClassPool cp, boolean isInterface,
@@ -24,8 +28,39 @@ class CtNewNestedClass extends CtNewClass {
super(realName, cp, isInterface, superclass);
}
+ /**
+ * This method does not change the STATIC bit. The original value is kept.
+ */
public void setModifiers(int mod) {
- super.setModifiers(Modifier.clear(mod,
- Modifier.STATIC | Modifier.PRIVATE));
+ mod = mod & ~Modifier.STATIC;
+ super.setModifiers(mod);
+ updateInnerEntry(mod, getName(), this, true);
+ }
+
+ private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) {
+ ClassFile cf = clazz.getClassFile2();
+ InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
+ InnerClassesAttribute.tag);
+ if (ica == null)
+ return;
+
+ int n = ica.tableLength();
+ for (int i = 0; i < n; i++)
+ if (name.equals(ica.innerClass(i))) {
+ int acc = ica.accessFlags(i) & AccessFlag.STATIC;
+ ica.setAccessFlags(i, mod | acc);
+ String outName = ica.outerClass(i);
+ if (outName != null && outer)
+ try {
+ CtClass parent = clazz.getClassPool().get(outName);
+ updateInnerEntry(mod, name, parent, false);
+ }
+ catch (NotFoundException e) {
+ throw new RuntimeException("cannot find the declaring class: "
+ + outName);
+ }
+
+ break;
+ }
}
}