Example usage for org.objectweb.asm TypeReference LOCAL_VARIABLE

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

Introduction

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

Prototype

int LOCAL_VARIABLE

To view the source code for org.objectweb.asm TypeReference LOCAL_VARIABLE.

Click Source Link

Document

The sort of type references that target the type of a local variable in a method.

Usage

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

License:Open Source License

@Override
public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef, final TypePath typePath,
        final Label[] start, final Label[] end, final int[] index, final String desc, final boolean visible) {
    /*/*from   ww w .j  ava  2 s. c  om*/
     * 3.3.7: The table length field specifies the number of entries in the table array;
     * multiple entries are necessary because a compiler is permitted to break a single variable
     * into multiple live ranges with different local variable indices. The start pc and length
     * fields specify the variables live range in the bytecodes of the local variables
     * containing method (from offset start pc, inclusive, to offset start pc + length,
     * exclusive). The index field stores the local variables index in that method. These
     * fields are similar to those of the optional LocalVariableTable attribute [LBBY12,
     * 4.8.12]. Storing local variable type annotations in the class file raises certain
     * challenges. For example, live ranges are not isomorphic to local variables. Note that a
     * local variable with no live range might not appear in the class file; that is OK, because
     * it is irrelevant to the program. A Runtime[In]visibleTypeAnnotations attribute containing
     * a localvar target appears in the attributes table of a Code attribute.
     */
    final A a = this.annotationVisitor.init(desc, visible ? RetentionPolicy.RUNTIME : RetentionPolicy.CLASS);
    if (a == null) {
        log.warn(getM() + ": Cannot read annotation for descriptor '" + desc + "'!");
        return null;
    }
    final TypeReference typeReference = new TypeReference(typeRef);
    switch (typeReference.getSort()) {
    case TypeReference.LOCAL_VARIABLE:
        for (int i = index.length; i-- > 0;) {
            final List<V> vs = this.reg2vs.get(index[i]);
            if (vs != null) {
                // TODO hmmm, we may have to remember this info (like receiver),
                // we cannot apply it without variable analysis in none-debug bytecode,
                // missing local variable tables! this whole new bytecode sucks
                for (final V v : vs) {
                    if (v.validIn(getPc(start[i]), getPc(end[i]))) {
                        v.setT(annotateT(v.getT(), a, typePath));
                    }
                }
            }
        }
        break;
    default:
        log.warn(
                getM() + ": Unknown type annotation ref sort '0x" + Integer.toHexString(typeReference.getSort())
                        + "' : " + typeRef + " : " + typePath + " : " + desc + " : " + visible);
    }
    return this.annotationVisitor;
}