01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
10: * Software distributed under the License is distributed on an "AS IS" basis,
11: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12: * for the specific language governing rights and limitations under the
13: * License.
14: */
15:
16: package javassist;
17:
18: import javassist.bytecode.ClassFile;
19: import javassist.bytecode.AccessFlag;
20: import javassist.bytecode.InnerClassesAttribute;
21:
22: /**
23: * A newly created public nested class.
24: */
25: class CtNewNestedClass extends CtNewClass {
26: CtNewNestedClass(String realName, ClassPool cp,
27: boolean isInterface, CtClass super class) {
28: super (realName, cp, isInterface, super class);
29: }
30:
31: /**
32: * This method does not change the STATIC bit. The original value is kept.
33: */
34: public void setModifiers(int mod) {
35: mod = mod & ~Modifier.STATIC;
36: super .setModifiers(mod);
37: updateInnerEntry(mod, getName(), this , true);
38: }
39:
40: private static void updateInnerEntry(int mod, String name,
41: CtClass clazz, boolean outer) {
42: ClassFile cf = clazz.getClassFile2();
43: InnerClassesAttribute ica = (InnerClassesAttribute) cf
44: .getAttribute(InnerClassesAttribute.tag);
45: if (ica == null)
46: return;
47:
48: int n = ica.tableLength();
49: for (int i = 0; i < n; i++)
50: if (name.equals(ica.innerClass(i))) {
51: int acc = ica.accessFlags(i) & AccessFlag.STATIC;
52: ica.setAccessFlags(i, mod | acc);
53: String outName = ica.outerClass(i);
54: if (outName != null && outer)
55: try {
56: CtClass parent = clazz.getClassPool().get(
57: outName);
58: updateInnerEntry(mod, name, parent, false);
59: } catch (NotFoundException e) {
60: throw new RuntimeException(
61: "cannot find the declaring class: "
62: + outName);
63: }
64:
65: break;
66: }
67: }
68: }
|