org.objectweb.asm.commons
类 SerialVersionUIDAdder

java.lang.Object
  继承者 org.objectweb.asm.ClassAdapter
      继承者 org.objectweb.asm.commons.SerialVersionUIDAdder
所有已实现的接口:
ClassVisitor

public class SerialVersionUIDAdder
extends ClassAdapter

A ClassAdapter that adds a serial version unique identifier to a class if missing. Here is typical usage of this class:

   ClassWriter cw = new ClassWriter(...);
   ClassVisitor sv = new SerialVersionUIDAdder(cw);
   ClassVisitor ca = new MyClassAdapter(sv);
   new ClassReader(orginalClass).accept(ca, false);
 
The SVUID algorithm can be found http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html:
 The serialVersionUID is computed using the signature of a stream of bytes
 that reflect the class definition. The National Institute of Standards and
 Technology (NIST) Secure Hash Algorithm (SHA-1) is used to compute a
 signature for the stream. The first two 32-bit quantities are used to form a
 64-bit hash. A java.lang.DataOutputStream is used to convert primitive data
 types to a sequence of bytes. The values input to the stream are defined by
 the Java Virtual Machine (VM) specification for classes.

 The sequence of items in the stream is as follows:

 1. The class name written using UTF encoding.
 2. The class modifiers written as a 32-bit integer.
 3. The name of each interface sorted by name written using UTF encoding.
 4. For each field of the class sorted by field name (except private static
 and private transient fields):
 1. The name of the field in UTF encoding.
 2. The modifiers of the field written as a 32-bit integer.
 3. The descriptor of the field in UTF encoding
 5. If a class initializer exists, write out the following:
 1. The name of the method, <clinit>, in UTF encoding.
 2. The modifier of the method, java.lang.reflect.Modifier.STATIC,
 written as a 32-bit integer.
 3. The descriptor of the method, ()V, in UTF encoding.
 6. For each non-private constructor sorted by method name and signature:
 1. The name of the method, <init>, in UTF encoding.
 2. The modifiers of the method written as a 32-bit integer.
 3. The descriptor of the method in UTF encoding.
 7. For each non-private method sorted by method name and signature:
 1. The name of the method in UTF encoding.
 2. The modifiers of the method written as a 32-bit integer.
 3. The descriptor of the method in UTF encoding.
 8. The SHA-1 algorithm is executed on the stream of bytes produced by
 DataOutputStream and produces five 32-bit values sha[0..4].

 9. The hash value is assembled from the first and second 32-bit values of 
 the SHA-1 message digest. If the result of the message digest, the five
 32-bit words H0 H1 H2 H3 H4, is in an array of five int values named 
 sha, the hash value would be computed as follows:

 long hash = ((sha[0] >>> 24) & 0xFF) |
 ((sha[0] >>> 16) & 0xFF) << 8 |
 ((sha[0] >>> 8) & 0xFF) << 16 |
 ((sha[0] >>> 0) & 0xFF) << 24 |
 ((sha[1] >>> 24) & 0xFF) << 32 |
 ((sha[1] >>> 16) & 0xFF) << 40 |
 ((sha[1] >>> 8) & 0xFF) << 48 |
 ((sha[1] >>> 0) & 0xFF) << 56;
 

作者:
Rajendra Inamdar, Vishal Vishnoi

字段摘要
protected  int access
          Classes access flags.
protected  boolean computeSVUID
          Flag that indicates if we need to compute SVUID.
protected  boolean hasStaticInitializer
          Set to true if the class has static initializer.
protected  boolean hasSVUID
          Set to true if the class already has SVUID.
protected  String[] interfaces
          Interfaces implemented by the class.
protected  String name
          Internal name of the class
protected  Collection svuidConstructors
          Collection of non-private constructors.
protected  Collection svuidFields
          Collection of fields.
protected  Collection svuidMethods
          Collection of non-private methods.
 
从类 org.objectweb.asm.ClassAdapter 继承的字段
cv
 
构造方法摘要
SerialVersionUIDAdder(ClassVisitor cv)
          Creates a new SerialVersionUIDAdder.
 
方法摘要
protected  byte[] computeSHAdigest(byte[] value)
          Returns the SHA-1 message digest of the given value.
protected  long computeSVUID()
          Returns the value of SVUID if the class doesn't have one already.
 void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
          Visits the header of the class.
 void visitEnd()
          Visits the end of the class.
 FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
          Visits a field of the class.
 MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
          Visits a method of the class.
 
从类 org.objectweb.asm.ClassAdapter 继承的方法
visitAnnotation, visitAttribute, visitInnerClass, visitOuterClass, visitSource
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

computeSVUID

protected boolean computeSVUID
Flag that indicates if we need to compute SVUID.


hasSVUID

protected boolean hasSVUID
Set to true if the class already has SVUID.


access

protected int access
Classes access flags.


name

protected String name
Internal name of the class


interfaces

protected String[] interfaces
Interfaces implemented by the class.


svuidFields

protected Collection svuidFields
Collection of fields. (except private static and private transient fields)


hasStaticInitializer

protected boolean hasStaticInitializer
Set to true if the class has static initializer.


svuidConstructors

protected Collection svuidConstructors
Collection of non-private constructors.


svuidMethods

protected Collection svuidMethods
Collection of non-private methods.

构造方法详细信息

SerialVersionUIDAdder

public SerialVersionUIDAdder(ClassVisitor cv)
Creates a new SerialVersionUIDAdder.

参数:
cv - a ClassVisitor to which this visitor will delegate calls.
方法详细信息

visit

public void visit(int version,
                  int access,
                  String name,
                  String signature,
                  String superName,
                  String[] interfaces)
从接口 ClassVisitor 复制的描述
Visits the header of the class.

指定者:
接口 ClassVisitor 中的 visit
覆盖:
ClassAdapter 中的 visit
参数:
version - the class version.
access - the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated.
name - the internal name of the class (see getInternalName).
signature - the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
superName - the internal of name of the super class (see getInternalName). For interfaces, the super class is Object. May be null, but only for the Object class.
interfaces - the internal names of the class's interfaces (see getInternalName). May be null.

visitMethod

public MethodVisitor visitMethod(int access,
                                 String name,
                                 String desc,
                                 String signature,
                                 String[] exceptions)
从接口 ClassVisitor 复制的描述
Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

指定者:
接口 ClassVisitor 中的 visitMethod
覆盖:
ClassAdapter 中的 visitMethod
参数:
access - the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
name - the method's name.
desc - the method's descriptor (see Type).
signature - the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
exceptions - the internal names of the method's exception classes (see getInternalName). May be null.
返回:
an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

visitField

public FieldVisitor visitField(int access,
                               String name,
                               String desc,
                               String signature,
                               Object value)
从接口 ClassVisitor 复制的描述
Visits a field of the class.

指定者:
接口 ClassVisitor 中的 visitField
覆盖:
ClassAdapter 中的 visitField
参数:
access - the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.
name - the field's name.
desc - the field's descriptor (see Type).
signature - the field's signature. May be null if the field's type does not use generic types.
value - the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.
返回:
a visitor to visit field annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

visitEnd

public void visitEnd()
从接口 ClassVisitor 复制的描述
Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

指定者:
接口 ClassVisitor 中的 visitEnd
覆盖:
ClassAdapter 中的 visitEnd

computeSVUID

protected long computeSVUID()
                     throws IOException
Returns the value of SVUID if the class doesn't have one already. Please note that 0 is returned if the class already has SVUID, thus use isHasSVUID to determine if the class already had an SVUID.

返回:
Returns the serial version UID
抛出:
IOException

computeSHAdigest

protected byte[] computeSHAdigest(byte[] value)
Returns the SHA-1 message digest of the given value.

参数:
value - the value whose SHA message digest must be computed.
返回:
the SHA-1 message digest of the given value.


Copyright © 2013. All Rights Reserved.