目录
1. spring-core 包概况
1. spring-core 包概况
1.1 ASM 包
概述:
ASM: a very small and fast Java bytecode manipulation framework
ASM: 一款非常小且快的java字节码操作框架
ASM包内结构:
Class-1. AnnotationVisitor
(1).Class简介:
A visitor to visit a Java annotation. The methods of this class must be called in the following order: ( visit | visitEnum | visitAnnotation | visitArray )visitEnd.
翻译:
访问Java注释的访问者。 这个类的方法必须是按以下顺序调用:(visit| visitEnum |visitAnnotation | visitArray)visitEnd。
(2). Class域:
protected final int api;
protected AnnotationVisitor av;
/**
* The ASM API version implemented by this visitor. The value of this field
* must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
*/
/*该访问者实施的ASM API版本。此字段的值必须是Opcodes.ASM4或Opcodes.ASM5之一。*/
protected final int api;
/**
* The annotation visitor to which this visitor must delegate method calls.
* May be null.
*/
/*该访问者必须委托方法调用的注释访问者。
可能为null。*/
protected AnnotationVisitor av;
(3).Class方法
- 构造方法
public AnnotationVisitor(final int api) {
this(api, null);
}
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
if (api != Opcodes.ASM4 && api != Opcodes.ASM5) {
throw new IllegalArgumentException();
}
this.api = api;
this.av = av;
}
//唯二的构造函数,给两个成员赋值,且api必须。
- 其他方法
visit:Visits a primitive value of the annotation.//访问注释的原始值
visitEnum:Visits an enumeration value of the annotation.//访问注释的枚举值
visitAnnotation:Visits a nested annotation value of the annotation.//访问嵌套的注释值
visitArray
/** Visits an array value of the annotation. Note that arrays of primitive
* types (such as byte, boolean, short, char, int, long, float or double)
* can be passed as value to {
@link #visit visit}. This is what
* {
@link ClassReader} does.
*/
//访问注释的数组值,注意原始类型可以作为值传递给visit方法。这是ClassReader类的实现方式。
visitEnd:Visits the end of the annotation.//访问annotation的结尾
- 方法总结
该类所有方法都是基于调用他的成员变量av:AnnotationVisitor的,有些类似于代理模式
(4).类总结
该类是抽象类,并且是访问注释的类的祖先,定义了一套规则,用于访问注释。
Class-2. AnnotationWriter
(1).Class简介:
An {
@link AnnotationVisitor} that generates annotations in bytecode form
//一个{@link AnnotationVisitor}的子类,以字节码形式生成注释
(2). Class域:
/**
* The class writer to which this annotation must be added.
* 翻译:必须添加此注释的ClassWriter
*/
private final ClassWriter cw;
/**
* The number of values in this annotation.
* 翻译:此注释中值的数量
*/
private int size;
/**
* <tt>true<tt> if values are named, <tt>false</tt> otherwise. Annotation writers used for annotation default and annotation arrays use unnamed values.
* 翻译:如果values被命名为true,否则为false。 用于注释缺省和注解数组的注释写入器使用未命名的值。
*/
private final boolean named;
/**
* The annotation values in bytecode form. This byte vector only contains the values themselves, i.e. the number of values must be stored as a unsigned short just before these bytes.
* 翻译:注释值以字节码形式显示。 该字节向量仅包含值本身,即值的数目必须在这些字节之前存储为无符号short类型的值。
*/
private final ByteVector bv;
/**
* The byte vector to be used to store the number of values of this annotation. See {@link #bv}.
* 翻译:用于存储此注释值的数量的字节向量。
*/
private final ByteVector parent;
/**
* Where the number of values of this annotation must be stored in {@link #parent}.
* 翻译:该注释