Search in sources :

Example 1 with InnerClassesAttribute

use of javassist.bytecode.InnerClassesAttribute in project powermock by powermock.

the class AbstractMainMockTransformer method removeFinalModifierFromClass.

protected void removeFinalModifierFromClass(final CtClass clazz) {
    if (strategy != INST_REDEFINE) {
        if (Modifier.isFinal(clazz.getModifiers())) {
            clazz.setModifiers(clazz.getModifiers() ^ Modifier.FINAL);
        }
        ClassFile classFile = clazz.getClassFile2();
        AttributeInfo attribute = classFile.getAttribute(InnerClassesAttribute.tag);
        if (attribute != null && attribute instanceof InnerClassesAttribute) {
            InnerClassesAttribute ica = (InnerClassesAttribute) attribute;
            String name = classFile.getName();
            int n = ica.tableLength();
            for (int i = 0; i < n; ++i) {
                if (name.equals(ica.innerClass(i))) {
                    int accessFlags = ica.accessFlags(i);
                    if (Modifier.isFinal(accessFlags)) {
                        ica.setAccessFlags(i, accessFlags ^ Modifier.FINAL);
                    }
                }
            }
        }
    }
}
Also used : AttributeInfo(javassist.bytecode.AttributeInfo) ClassFile(javassist.bytecode.ClassFile) InnerClassesAttribute(javassist.bytecode.InnerClassesAttribute)

Aggregations

AttributeInfo (javassist.bytecode.AttributeInfo)1 ClassFile (javassist.bytecode.ClassFile)1 InnerClassesAttribute (javassist.bytecode.InnerClassesAttribute)1