Package limpidlog.asm1

Source Code of limpidlog.asm1.MethodPreVisitor

//Copyright 2006-2007 Acelet Corporation. All rights reserved.

package limpidlog.asm1;

import java.util.*;
import limpidlog.org.objectweb.asm.Label;
import limpidlog.org.objectweb.asm.MethodAdapter;
import limpidlog.org.objectweb.asm.MethodVisitor;
import limpidlog.org.objectweb.asm.Opcodes;
import limpidlog.org.objectweb.asm.Type;

/**
* @author Wei Jiang
*/

public class MethodPreVisitor extends MethodAdapter {
  int access;
  String methodName;
  String descriptor;
  Hashtable lableVariableHashtable;
  Type[] argumentTypes;
  boolean isStatic;

  Vector labelVector;
  Vector localVariableVector = new Vector();

  MethodPreVisitor(MethodVisitor mv, int access, String methodName, String descriptor,
  Vector labelVector, Hashtable lableVariableHashtable) {
    super(mv);
    this.access = access;
    this.methodName = methodName;
    this.descriptor = descriptor;
    this.lableVariableHashtable = lableVariableHashtable;
    this.labelVector = labelVector;
    argumentTypes = Type.getArgumentTypes(descriptor);
    isStatic = ((access & Opcodes.ACC_STATIC) > 0);
  }

  public void visitLabel(Label label) {
    super.visitLabel(label);

    labelVector.add(label);
  }

  public void visitEnd() {
    super.visitEnd();

    for (int i = 0; i < labelVector.size(); i++) {
      Vector vector = new Vector();

      Label label = (Label) labelVector.elementAt(i);
      int offset = label.getOffset();
      for (int var = 0; var < localVariableVector.size(); var++) {
        LocalVariable localVariable = (LocalVariable) localVariableVector.get(var);
        String name = localVariable.name;
        if (name.equals("this"))
          continue;

        if (offset >= localVariable.startOffset && offset < localVariable.endOffset)
          vector.add(localVariable);
      }
      lableVariableHashtable.put(label, vector);
    }
  }

  public void visitLocalVariable(String name, String desc, String signature,
  Label start, Label end, int index) {
    super.visitLocalVariable(name, desc, signature, start, end, index);

    LocalVariable localVariable = new LocalVariable(name, desc, signature, start, end, index);
    localVariableVector.add(localVariable);
  }
}
TOP

Related Classes of limpidlog.asm1.MethodPreVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.