1. 代码结构
org.apache.ibatis.reflection
2. 反射基类 org.apache.ibatis.reflection.Reflector
主要针对传递的class对象通过反射自动解析出对应的get,set方法
2.1.1 org.apache.ibatis.reflection.invoker.Invoker
通过反射获取的field,method的调用处理类
2.2 . 反射工厂 org.apache.ibatis.reflection.ReflectorFactory
反射工厂主要为了提升Reflector 的初始化速度, 对Reflector对象进行缓存,最核心的方法是用来获取Reflector对象的findClass方法,
org.apache.ibatis.reflection.DefaultReflectorFactory
org.apache.ibatis.reflection.ReflectorFactory
org.apache.ibatis.reflection.DefaultReflectorFactory#findForClass
@Override
public Reflector findForClass(Class<?> type) {
if (classCacheEnabled) {
// synchronized (type) removed see issue #461
return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new);
} else {
return new Reflector(type);
}
}
3. 默认对象工厂org.apache.ibatis.reflection.factory.ObjectFactory
顾名思义负责对象的自动创建,通过传入class对象自动根据入参选择对应的构造器进行创建
3.1 org.apache.ibatis.reflection.factory.ObjectFactory
3.2 org.apache.ibatis.reflection.factory.DefaultObjectFactory
4. 类信息处理类 org.apache.ibatis.reflection.MetaClass
5. 对象处理基类org.apache.ibatis.reflection.MetaObject
6 . org.apache.ibatis.reflection.wrapper.ObjectWrapper
7. 属性分词器 org.apache.ibatis.reflection.property.PropertyTokenizer
7.1 分词逻辑
org.apache.ibatis.reflection.property.PropertyTokenizer
private String name;
private final String indexedName;
private String index;
private final String children;
public PropertyTokenizer(String fullname) {
int delim = fullname.indexOf('.');
if (delim > -1) {
name = fullname.substring(0, delim);
children = fullname.substring(delim + 1);
} else {
name = fullname;
children = null;
}
indexedName = name;
delim = name.indexOf('[');
if (delim > -1) {
index = name.substring(delim + 1, name.length() - 1);
name = name.substring(0, delim);
}
}