FileDocCategorySizeDatePackage
AbstractClassAdapter.javaAPI DocAndroid 5.1 API14114Thu Mar 12 22:22:44 GMT 2015com.android.tools.layoutlib.create

AbstractClassAdapter

public abstract class AbstractClassAdapter extends org.objectweb.asm.ClassVisitor
Provides the common code for RenameClassAdapter and RefactorClassAdapter. It goes through the complete class and finds references to other classes. It then calls {@link #renameInternalType(String)} to convert the className to the new value, if need be.

Fields Summary
Constructors Summary
public AbstractClassAdapter(org.objectweb.asm.ClassVisitor cv)

        super(Opcodes.ASM4, cv);
    
Methods Summary
java.lang.StringrenameFieldSignature(java.lang.String sig)
Renames the FieldTypeSignature handled by ClassVisitor.visitField or MethodVisitor.visitLocalVariable.

        return renameTypeSignature(sig);
    
abstract java.lang.StringrenameInternalType(java.lang.String name)
Returns the new FQCN for the class, if the reference to this class needs to be updated. Else, it returns the same string.

param
name Old FQCN
return
New FQCN if it needs to be renamed, else the old FQCN

java.lang.StringrenameMethodDesc(java.lang.String desc)
Renames a method descriptor, i.e. applies renameType to all arguments and to the return value.

        if (desc == null) {
            return null;
        }

        Type[] args = Type.getArgumentTypes(desc);

        StringBuilder sb = new StringBuilder("(");
        for (Type arg : args) {
            String name = renameType(arg);
            sb.append(name);
        }
        sb.append(')");

        Type ret = Type.getReturnType(desc);
        String name = renameType(ret);
        sb.append(name);

        return sb.toString();
    
java.lang.StringrenameType(org.objectweb.asm.Type type)
Renames an object type, e.g. "Lcom.package.MyClass;" or an array type that has an object element, e.g. "[Lcom.package.MyClass;" If the type doesn't need to be renamed, returns the internal name of the input type.

        if (type == null) {
            return null;
        }

        if (type.getSort() == Type.OBJECT) {
            String in = type.getInternalName();
            return "L" + renameInternalType(in) + ";";
        } else if (type.getSort() == Type.ARRAY) {
            StringBuilder sb = new StringBuilder();
            for (int n = type.getDimensions(); n > 0; n--) {
                sb.append('[");
            }
            sb.append(renameType(type.getElementType()));
            return sb.toString();
        }
        return type.getDescriptor();
    
org.objectweb.asm.TyperenameTypeAsType(org.objectweb.asm.Type type)
Renames an object type, e.g. "Lcom.package.MyClass;" or an array type that has an object element, e.g. "[Lcom.package.MyClass;". This is like renameType() except that it returns a Type object. If the type doesn't need to be renamed, returns the input type object.

        if (type == null) {
            return null;
        }

        if (type.getSort() == Type.OBJECT) {
            String in = type.getInternalName();
            String newIn = renameInternalType(in);
            if (!newIn.equals(in)) {
                return Type.getType("L" + newIn + ";");
            }
        } else if (type.getSort() == Type.ARRAY) {
            StringBuilder sb = new StringBuilder();
            for (int n = type.getDimensions(); n > 0; n--) {
                sb.append('[");
            }
            sb.append(renameType(type.getElementType()));
            return Type.getType(sb.toString());
        }
        return type;
    
java.lang.StringrenameTypeDesc(java.lang.String desc)
Renames a type descriptor, e.g. "Lcom.package.MyClass;" If the type doesn't need to be renamed, returns the input string as-is.

        if (desc == null) {
            return null;
        }

        return renameType(Type.getType(desc));
    
java.lang.StringrenameTypeSignature(java.lang.String sig)
Renames the ClassSignature handled by ClassVisitor.visit or the MethodTypeSignature handled by ClassVisitor.visitMethod.

        if (sig == null) {
            return null;
        }
        SignatureReader reader = new SignatureReader(sig);
        SignatureWriter writer = new SignatureWriter();
        reader.accept(new RenameSignatureAdapter(writer));
        sig = writer.toString();
        return sig;
    
public voidvisit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)

        name = renameInternalType(name);
        superName = renameInternalType(superName);
        signature = renameTypeSignature(signature);
        if (interfaces != null) {
            for (int i = 0; i < interfaces.length; ++i) {
                interfaces[i] = renameInternalType(interfaces[i]);
            }
        }

        /* Java 7 verifies the StackMapTable of a class if its version number is greater than 50.0.
         * However, the check is disabled if the class version number is 50.0 or less. Generation
         * of the StackMapTable requires a rewrite using the tree API of ASM. As a workaround,
         * we rewrite the version number of the class to be 50.0
         *
         * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6693236
         */
        if (version > 50) {
            version = 50;
        }

        super.visit(version, access, name, signature, superName, interfaces);
    
public org.objectweb.asm.AnnotationVisitorvisitAnnotation(java.lang.String desc, boolean visible)

        desc = renameTypeDesc(desc);
        return super.visitAnnotation(desc, visible);
    
public org.objectweb.asm.FieldVisitorvisitField(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.Object value)

        desc = renameTypeDesc(desc);
        return super.visitField(access, name, desc, signature, value);
    
public voidvisitInnerClass(java.lang.String name, java.lang.String outerName, java.lang.String innerName, int access)

        name = renameInternalType(name);
        outerName = renameInternalType(outerName);
        super.visitInnerClass(name, outerName, innerName, access);
    
public org.objectweb.asm.MethodVisitorvisitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)

        desc = renameMethodDesc(desc);
        signature = renameTypeSignature(signature);
        MethodVisitor mw = super.visitMethod(access, name, desc, signature, exceptions);
        return new RenameMethodAdapter(mw);
    
public voidvisitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String desc)

        super.visitOuterClass(renameInternalType(owner), name, renameTypeDesc(desc));