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);
  }
Пример #2
0
  /** Loads the line numbers for the method. */
  protected int[] loadLineNumbers(Method m) {
    Code c = m.getCode();

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

    LineNumberTable lnt = c.getLineNumberTable();

    int length = code.length;
    int[] ln = new int[length];

    if (lnt == null) {
      // no line information
      return null;
    } else {
      for (int i = 0; i < length; i++) {
        try { // annoying bug when BCEL don't seem to find linenumber - pos match
          ln[i] = lnt.getSourceLine(code[i].getPosition());
        } catch (RuntimeException e) {
          System.out.print("^");
        }
      }
    }

    return ln;
  }
  @Override
  public void sawOpcode(int seen) {
    if (ifInstructionSet.get(seen)) {
      if (getBranchTarget() == getBranchFallThrough()) {
        int priority = NORMAL_PRIORITY;

        LineNumberTable lineNumbers = getCode().getLineNumberTable();
        if (lineNumbers != null) {
          int branchLineNumber = lineNumbers.getSourceLine(getPC());
          int targetLineNumber = lineNumbers.getSourceLine(getBranchFallThrough());
          int nextLine = getNextSourceLine(lineNumbers, branchLineNumber);

          if (branchLineNumber + 1 == targetLineNumber
              || branchLineNumber == targetLineNumber && nextLine == branchLineNumber + 1)
            priority = HIGH_PRIORITY;
          else if (branchLineNumber + 2 < Math.max(targetLineNumber, nextLine))
            priority = LOW_PRIORITY;
        } else priority = LOW_PRIORITY;
        bugAccumulator.accumulateBug(
            new BugInstance(
                    this,
                    priority == HIGH_PRIORITY
                        ? "UCF_USELESS_CONTROL_FLOW_NEXT_LINE"
                        : "UCF_USELESS_CONTROL_FLOW",
                    priority)
                .addClassAndMethod(this),
            this);
      }
    }
  }
Пример #4
0
 /* 111:    */
 /* 112:    */ public Attribute copy(ConstantPool constant_pool) /* 113:    */ {
   /* 114:223 */ LineNumberTable c = (LineNumberTable) clone();
   /* 115:    */
   /* 116:225 */ c.line_number_table = new LineNumber[this.line_number_table_length];
   /* 117:226 */ for (int i = 0; i < this.line_number_table_length; i++) {
     /* 118:227 */ c.line_number_table[i] = this.line_number_table[i].copy();
     /* 119:    */ }
   /* 120:229 */ c.constant_pool = constant_pool;
   /* 121:230 */ return c;
   /* 122:    */ }
  public static int getNextSourceLine(LineNumberTable lineNumbers, int sourceLine) {
    int result = Integer.MAX_VALUE;
    for (LineNumber ln : lineNumbers.getLineNumberTable()) {

      int thisLine = ln.getLineNumber();
      if (sourceLine < thisLine && thisLine < result) result = thisLine;
    }
    return result;
  }
Пример #6
0
 /*  12:    */
 /*  13:    */ public LineNumberTable(LineNumberTable c) /*  14:    */ {
   /*  15: 79 */ this(
       c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool());
   /*  16:    */ }