public CtClass getDeclaringClass() throws NotFoundException {
        ClassFile cf = getClassFile2();
        InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
                                                InnerClassesAttribute.tag);
        if (ica == null)
            return null;

        String name = getName();
        int n = ica.tableLength();
        for (int i = 0; i < n; ++i)
            if (name.equals(ica.innerClass(i))) {
                String outName = ica.outerClass(i);
                if (outName != null)
                    return classPool.get(outName);
                else {
                    // maybe anonymous or local class.
                    EnclosingMethodAttribute ema
                        = (EnclosingMethodAttribute)cf.getAttribute(
                                                    EnclosingMethodAttribute.tag);
                    if (ema != null)
                        return classPool.get(ema.className());
                }
            }

        return null;
    }