Example usage for org.objectweb.asm TypeReference getSuperTypeIndex

List of usage examples for org.objectweb.asm TypeReference getSuperTypeIndex

Introduction

In this page you can find the example usage for org.objectweb.asm TypeReference getSuperTypeIndex.

Prototype

public int getSuperTypeIndex() 

Source Link

Document

Returns the index of the "super type" of a class that is referenced by this type reference.

Usage

From source file:org.decojer.cavaj.readers.asm.ReadClassVisitor.java

License:Open Source License

@Override
public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc,
        final boolean visible) {
    final A a = this.readAnnotationMemberVisitor.init(desc,
            visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS);
    if (a == null) {
        log.warn(getT() + ": Cannot read annotation for descriptor '" + desc + "'!");
        return null;
    }/*from w  ww .j  a  va  2 s. co m*/
    final TypeReference typeReference = new TypeReference(typeRef);
    switch (typeReference.getSort()) {
    case TypeReference.CLASS_EXTENDS: {
        final int superTypeIndex = typeReference.getSuperTypeIndex();
        if (superTypeIndex == -1) {
            // -1: annotation targets extends type
            final T superT = getT().getSuperT();
            if (superT == null) {
                log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing super type!");
                break;
            }
            getT().setSuperT(annotateT(superT, a, typePath));
            break;
        }
        // 0-based interface index
        final T[] interfaceTs = getT().getInterfaceTs();
        if (superTypeIndex <= interfaceTs.length) {
            log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing interface type at index '"
                    + superTypeIndex + "'!");
            break;
        }
        final T interfaceT = interfaceTs[superTypeIndex];
        assert interfaceT != null;
        interfaceTs[superTypeIndex] = annotateT(interfaceT, a, typePath);
        break;
    }
    case TypeReference.CLASS_TYPE_PARAMETER: {
        final int typeParameterIndex = typeReference.getTypeParameterIndex();
        final T[] typeParams = getT().getTypeParams();
        if (typeParams.length <= typeParameterIndex) {
            log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing type parameter at index '"
                    + typeParameterIndex + "'!");
            break;
        }
        final T typeParam = typeParams[typeParameterIndex];
        assert typeParam != null;
        typeParams[typeParameterIndex] = annotateT(typeParam, a, typePath);
        break;
    }
    case TypeReference.CLASS_TYPE_PARAMETER_BOUND: {
        final int typeParameterIndex = typeReference.getTypeParameterIndex();
        final int typeParameterBoundIndex = typeReference.getTypeParameterBoundIndex();
        final T t = getT().getTypeParams()[typeParameterIndex];
        if (typeParameterBoundIndex == 0) {
            // 0: annotation targets extends type
            final T superT = t.getSuperT();
            if (superT == null) {
                log.warn(getT() + ": Cannot apply type annotation '" + a
                        + "' to missing type parameter bound super type!");
                break;
            }
            t.setSuperT(annotateT(superT, a, typePath));
            break;
        }
        // 1-based interface index
        final T[] interfaceTs = t.getInterfaceTs();
        if (interfaceTs.length <= typeParameterBoundIndex - 1) {
            log.warn(getT() + ": Cannot apply type annotation '" + a + "' to missing interface type at index '"
                    + (typeParameterBoundIndex - 1) + "'!");
            break;
        }
        final T interfaceT = interfaceTs[typeParameterBoundIndex - 1];
        assert interfaceT != null;
        interfaceTs[typeParameterBoundIndex - 1] = annotateT(interfaceT, a, typePath);
        break;
    }
    default:
        log.warn(
                this.t + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort())
                        + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible);
    }
    return this.readAnnotationMemberVisitor;
}