Package limpidlog.asm1

Source Code of limpidlog.asm1.Bytecoder1

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

package limpidlog.asm1;

import java.io.*;
import java.net.*;
import java.util.*;
import limpidlog.org.objectweb.asm.ClassReader;
import limpidlog.lib.Bytecoder;
import limpidlog.lib.Options;

/**
* @author Wei Jiang
*/

public class Bytecoder1 implements Bytecoder {
  boolean containsDebugInfo = false;

  public Bytecoder1() {
  }

  public boolean getContainsDebugInfo() {
    return containsDebugInfo;
  }

  public synchronized byte[] getModifiedClassBytes(String className, byte[] classBytes) {
    if (Options.debug)
      System.out.println("Bytecoder1.getModifiedClassBytes: " + className +
        " classBytes=" + classBytes.length);

    ClassReader classReader = new ClassReader(classBytes);
    ClassPreVisitor classPreVisitor = new ClassPreVisitor();
    classReader.accept(classPreVisitor, ClassReader.EXPAND_FRAMES);
    Hashtable localVariableVectorHashtable = classPreVisitor.localVariableVectorHashtable;
    Hashtable labelVectorHashtable = classPreVisitor.labelVectorHashtable;

    MyClassWriter myClassWriter =
      new MyClassWriter(labelVectorHashtable, localVariableVectorHashtable);
    classReader = new ClassReader(classBytes);

    if (Options.debug)
      System.out.println("Bytecoder1.getModifiedClassBytes: " +
        "before accept: className="+className+" classBytes=" + classBytes.length);

    classReader.accept(myClassWriter, 0);
    containsDebugInfo = myClassWriter.containsDebugInfo;

    byte[] bytes = null;
    if (Options.forceTransform || containsDebugInfo)
      bytes = myClassWriter.toByteArray();

    if (Options.debug)
      System.out.println("Bytecoder1.getModifiedClassBytes: " +
        "className=" + className +
        " length: " + classBytes.length + " -> " + ((bytes==null)? 0: bytes.length) +
        " forceTransform=" + Options.forceTransform + " containsDebugInfo=" + containsDebugInfo);
   
    return bytes;
  }

  public String getVersion() {
    return "Bytecoder1.";
  }

}
TOP

Related Classes of limpidlog.asm1.Bytecoder1

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.