Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public void visit(ClassFile file) throws Exception {
    List<MethodInfo> methods = file.getMethods();
    for (MethodInfo mi : methods) {
      try {
        CodeAttribute codeAttribute = mi.getCodeAttribute();
        // ignore abstract methods
        if (codeAttribute == null) {
          continue;
        }

        final int maxStack = codeAttribute.getMaxStack();
        int modified = 0;

        for (MethodRewriter mr : rewriters) {
          modified += mr.visit(mi);
        }

        if (modified != 0) {
          codeAttribute.setMaxStack(maxStack + modified);
        }
      } catch (Exception e) {
        throw new IllegalStateException("Cannot rewrite method: " + mi, e);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Constructs a copy of <code>Code_attribute</code>. Specified class names are replaced during the
   * copy.
   *
   * @param cp constant pool table.
   * @param src source Code attribute.
   * @param classnames pairs of replaced and substituted class names.
   */
  private CodeAttribute(ConstPool cp, CodeAttribute src, Map classnames) throws BadBytecode {
    super(cp, tag);

    maxStack = src.getMaxStack();
    maxLocals = src.getMaxLocals();
    exceptions = src.getExceptionTable().copy(cp, classnames);
    attributes = new ArrayList();
    List src_attr = src.getAttributes();
    int num = src_attr.size();
    for (int i = 0; i < num; ++i) {
      AttributeInfo ai = (AttributeInfo) src_attr.get(i);
      attributes.add(ai.copy(cp, classnames));
    }

    info = src.copyCode(cp, classnames, exceptions, this);
  }