public static LocalVariableAnnotation getLocalVariableAnnotation(
      Method method, int local, int position1, int position2) {

    LocalVariableTable localVariableTable = method.getLocalVariableTable();
    String localName = "?";
    if (localVariableTable != null) {
      LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1);
      if (lv1 == null) {
        lv1 = localVariableTable.getLocalVariable(local, position2);
        position1 = position2;
      }
      if (lv1 != null) localName = lv1.getName();
      else
        for (LocalVariable lv : localVariableTable.getLocalVariableTable()) {
          if (lv.getIndex() == local) {
            if (!localName.equals("?") && !localName.equals(lv.getName())) {
              // not a single consistent name
              localName = "?";
              break;
            }
            localName = lv.getName();
          }
        }
    }
    LineNumberTable lineNumbers = method.getLineNumberTable();
    if (lineNumbers == null) return new LocalVariableAnnotation(localName, local, position1);
    int line = lineNumbers.getSourceLine(position1);
    return new LocalVariableAnnotation(localName, local, position1, line);
  }
Esempio n. 2
0
 /**
  * Initialize from another object. Note that both objects use the same references (shallow copy).
  * Use copy() for a physical copy.
  *
  * @param c
  */
 public LocalVariable(LocalVariable c) {
   this(
       c.getStartPC(),
       c.getLength(),
       c.getNameIndex(),
       c.getSignatureIndex(),
       c.getIndex(),
       c.getConstantPool());
 }