Example usage for org.aspectj.apache.bcel.classfile JavaClass getSuperclassNameIndex

List of usage examples for org.aspectj.apache.bcel.classfile JavaClass getSuperclassNameIndex

Introduction

In this page you can find the example usage for org.aspectj.apache.bcel.classfile JavaClass getSuperclassNameIndex.

Prototype

public int getSuperclassNameIndex() 

Source Link

Usage

From source file:org.caesarj.mixer.intern.ClassModifyingVisitor.java

License:Open Source License

protected JavaClass transform(JavaClass clazz) throws MixerException {
    // empty collection of anonymous inner classes
    anonymousInners = new Vector<String>();

    oldOuterClassName = Tools.getOuterClass(clazz, oldClassName);
    oldSuperclassName = clazz.getSuperclassName();

    // create a copy as work base
    JavaClass newClass = clazz.copy();

    // find indices of class and super class name
    int classNameIndex = newClass.getClassNameIndex(), superclassNameIndex = newClass.getSuperclassNameIndex();
    ConstantClass cc = (ConstantClass) newClass.getConstantPool().getConstant(classNameIndex),
            csc = (ConstantClass) newClass.getConstantPool().getConstant(superclassNameIndex);
    classNameIndex = cc.getNameIndex();/*from   ww w .  jav  a  2  s .c  o  m*/
    superclassNameIndex = csc.getNameIndex();

    // Set new class & superclass name
    newClass.getConstantPool().setConstant(superclassNameIndex, new ConstantUtf8(newSuperclassName));
    newClass.getConstantPool().setConstant(classNameIndex, new ConstantUtf8(newClassName));

    // visit fields, methods and local variables to replace type references
    new DescendingVisitor(newClass, this).visit();

    // Delete all inner class references 
    Attribute[] atts = newClass.getAttributes();
    Vector<Attribute> v = new Vector<Attribute>();
    for (int i = 0; i < atts.length; i++) {
        Attribute attribute = atts[i];
        if (attribute.getTag() == Constants.ATTR_INNER_CLASSES) {
            InnerClasses ic = (InnerClasses) attribute;
            ic.setInnerClasses(new InnerClass[0]);
            ic.setLength(2);

        }
        v.add(attribute);
    }
    atts = v.toArray(new Attribute[v.size()]);
    newClass.setAttributes(atts);

    newClass = removeFactoryMethods(newClass);

    // Mixin classes must be abstract, because they do not implement factory methods,
    // (if the class is final => it was a anonymous inner class)
    if (!newClass.isFinal()) {
        newClass.setAccessFlags(newClass.getAccessFlags() | Constants.ACC_ABSTRACT);
    }

    // take a look at all methodrefs
    modifyMethodAndFieldRefs(newClass);

    // return generated class
    return newClass;
}