Skip to content
Closed

te #1502

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* <p>Mainly for use within the framework, but to some degree also
* useful for application classes.
*
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Rob Harrop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

/**
* General utility methods for working with annotations in JavaBeans style.
*
* <p>通用工具方法,工作在有annotation的JavaBeans style类
*
* @author Rob Harrop
* @author Juergen Hoeller
Expand All @@ -39,6 +41,8 @@ public abstract class AnnotationBeanUtils {
/**
* Copy the properties of the supplied {@link Annotation} to the supplied target bean.
* Any properties defined in {@code excludedProperties} will not be copied.
*
* <p>根据提供的Annotation负责属性给目标对象bean,排除excludedProperties包括的属性
* @param ann the annotation to copy from
* @param bean the bean instance to copy to
* @param excludedProperties the names of excluded properties, if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* <p>This is primarily designed to avoid clashes between a regular CGLIB
* version (used by some other library) and Spring's embedded variant,
* in case the same class happens to get proxied for different purposes.
*
* <p>CGLIB's DefaultNamingPolicy通用扩展
* @author Juergen Hoeller
* @since 3.2.8
*/
Expand Down
28 changes: 26 additions & 2 deletions spring-core/src/main/java/org/springframework/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@
* recognize the same names as the constants themselves, and freeing them
* from maintaining their own mapping.
*
* <p>该类可以用于parse其他类存在的public static final 定义的常量 ,该类的 {@code asXXXX}方法
* 允许通过string name访问常量值
* <p> 该类在PropertyEditors使用,可以让他们识别相同的name作为常量,可以释放他们从维护自己的映射中
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 16.03.2003
*/
public class Constants {

/** The name of the introspected class */
/** The name of the introspected class 要parse的类的类名 */
private final String className;

/** Map from String field name to object value */
/** Map from String field name to object value sting字段名对应于对象的值 */
private final Map<String, Object> fieldCache = new HashMap<>();


/**
* Create a new Constants converter class wrapping the given class.
* <p>All <b>public</b> static final variables will be exposed, whatever their type.
* 创建一个常量转换类wrapper给定的类,
* @param clazz the class to analyze
* @throws IllegalArgumentException if the supplied {@code clazz} is {@code null}
*/
Expand All @@ -79,13 +84,15 @@ public Constants(Class<?> clazz) {

/**
* Return the name of the analyzed class.
* 返回这个分析类的名称
*/
public final String getClassName() {
return this.className;
}

/**
* Return the number of constants exposed.
* 暴露的类的常量数
*/
public final int getSize() {
return this.fieldCache.size();
Expand All @@ -94,6 +101,8 @@ public final int getSize() {
/**
* Exposes the field cache to subclasses:
* a Map from String field name to object value.
*
* 暴露类的字段缓存
*/
protected final Map<String, Object> getFieldCache() {
return this.fieldCache;
Expand All @@ -102,6 +111,7 @@ protected final Map<String, Object> getFieldCache() {

/**
* Return a constant value cast to a Number.
* 返回常量值转换为Number
* @param code the name of the field (never {@code null})
* @return the Number value
* @see #asObject
Expand All @@ -118,6 +128,7 @@ public Number asNumber(String code) throws ConstantException {

/**
* Return a constant value as a String.
* 返回常量值转换为String
* @param code the name of the field (never {@code null})
* @return the String value
* Works even if it's not a string (invokes {@code toString()}).
Expand All @@ -132,6 +143,8 @@ public String asString(String code) throws ConstantException {
* Parse the given String (upper or lower case accepted) and return
* the appropriate value if it's the name of a constant field in the
* class that we're analysing.
*
* 返回常量值转换为Object
* @param code the name of the field (never {@code null})
* @return the Object value
* @throws ConstantException if there's no such field
Expand All @@ -154,6 +167,8 @@ public Object asObject(String code) throws ConstantException {
* values (i.e. all uppercase). The supplied {@code namePrefix}
* will be uppercased (in a locale-insensitive fashion) prior to
* the main logic of this method kicking in.
*
* 返回所有常量的名称根据前缀
* @param namePrefix prefix of the constant names to search (may be {@code null})
* @return the set of constant names
*/
Expand All @@ -171,6 +186,7 @@ public Set<String> getNames(String namePrefix) {
/**
* Return all names of the group of constants for the
* given bean property name.
* 返回所有常量名,根据给定bean属性的名称
* @param propertyName the name of the bean property
* @return the set of values
* @see #propertyToConstantNamePrefix
Expand All @@ -181,6 +197,8 @@ public Set<String> getNamesForProperty(String propertyName) {

/**
* Return all names of the given group of constants.
*
* 根据后缀返回给定常量名
* <p>Note that this method assumes that constants are named
* in accordance with the standard Java convention for constant
* values (i.e. all uppercase). The supplied {@code nameSuffix}
Expand All @@ -203,6 +221,7 @@ public Set<String> getNamesForSuffix(String nameSuffix) {

/**
* Return all values of the given group of constants.
* 根据前缀返回所有常量值
* <p>Note that this method assumes that constants are named
* in accordance with the standard Java convention for constant
* values (i.e. all uppercase). The supplied {@code namePrefix}
Expand All @@ -225,6 +244,7 @@ public Set<Object> getValues(String namePrefix) {
/**
* Return all values of the group of constants for the
* given bean property name.
* 返回所有常量值,根据给定bean属性的名称
* @param propertyName the name of the bean property
* @return the set of values
* @see #propertyToConstantNamePrefix
Expand All @@ -235,6 +255,7 @@ public Set<Object> getValuesForProperty(String propertyName) {

/**
* Return all values of the given group of constants.
* 根据前缀获取常量值
* <p>Note that this method assumes that constants are named
* in accordance with the standard Java convention for constant
* values (i.e. all uppercase). The supplied {@code nameSuffix}
Expand All @@ -257,6 +278,7 @@ public Set<Object> getValuesForSuffix(String nameSuffix) {

/**
* Look up the given value within the given group of constants.
* 根据前缀查找给定值和属性名key
* <p>Will return the first match.
* @param value constant value to look up
* @param namePrefix prefix of the constant names to search (may be {@code null})
Expand Down Expand Up @@ -288,7 +310,9 @@ public String toCodeForProperty(Object value, String propertyName) throws Consta

/**
* Look up the given value within the given group of constants.
*
* <p>Will return the first match.
* 根据后缀查找给定值和属性名key
* @param value constant value to look up
* @param nameSuffix suffix of the constant names to search (may be {@code null})
* @return the name of the constant field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Interface to be implemented by objects that can return information about
* the current call stack. Useful in AOP (as in AspectJ cflow concept)
* but not AOP-specific.
*
* 通过实现该接口,能返回当前调用stack信息,AOP 中使用,但不是AOP-specific
* @author Rod Johnson
* @since 02.02.2004
*/
Expand All @@ -29,20 +29,23 @@ public interface ControlFlow {
/**
* Detect whether we're under the given class,
* according to the current stack trace.
* 检查我们是否在给定class下,根据当前stack trace
* @param clazz the clazz to look for
*/
boolean under(Class<?> clazz);

/**
/**检查我们是否在给定class和方法下,根据当前stack trace
* Detect whether we're under the given class and method,
* according to the current stack trace.
*
* @param clazz the clazz to look for
* @param methodName the name of the method to look for
*/
boolean under(Class<?> clazz, String methodName);

/**
* Detect whether the current stack trace contains the given token.
* 检查我们是否在给定token下,根据当前stack trace
* @param token the token to look for
*/
boolean underToken(String token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*
* <p>This implementation always uses the efficient Java 1.4 StackTraceElement
* mechanism for analyzing control flows.
*
*
* <p>静态工程类隐藏自动选择ControlFlow的实现类
* 通常用于jdk1.4分析control flows
* @author Rod Johnson
* @author Juergen Hoeller
* @since 02.02.2004
Expand All @@ -36,6 +38,7 @@ public abstract class ControlFlowFactory {

/**
* Return an appropriate {@link ControlFlow} instance.
* 返回一个合适的ControlFlow实例
*/
public static ControlFlow createControlFlow() {
return new Jdk14ControlFlow();
Expand All @@ -47,7 +50,12 @@ public static ControlFlow createControlFlow() {
* 5-10 times more expensive to evaluate than other pointcuts, as they require
* analysis of the stack trace (through constructing a new throwable).
* However, they are useful in some cases.
*
* <p>This implementation uses the StackTraceElement class introduced in Java 1.4.
*
* <p>cflow-style 切面工具,比其他切面要耗性能5-10倍,因为需要分析stack trace
* 这个实现在jdk1.4引入StackTraceElement
*
* @see java.lang.StackTraceElement
*/
static class Jdk14ControlFlow implements ControlFlow {
Expand All @@ -60,6 +68,8 @@ public Jdk14ControlFlow() {

/**
* Searches for class name match in a StackTraceElement.
*
* 检查类名是否有匹配的在StackTraceElement中
*/
@Override
public boolean under(Class<?> clazz) {
Expand All @@ -76,6 +86,7 @@ public boolean under(Class<?> clazz) {
/**
* Searches for class name match plus method name match
* in a StackTraceElement.
* 检查类名和方法是否有匹配的在StackTraceElement中
*/
@Override
public boolean under(Class<?> clazz, String methodName) {
Expand All @@ -94,6 +105,8 @@ public boolean under(Class<?> clazz, String methodName) {
/**
* Leave it up to the caller to decide what matches.
* Caller must understand stack trace format, so there's less abstraction.
* 检查token是否有匹配的在StackTraceElement中
*
*/
@Override
public boolean underToken(String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Provides methods to support various naming and other conventions used
* throughout the framework. Mainly for internal use within the framework.
*
* <p> 提供方法去支持不通的命名和其他用于该framewokr,主要用于内部使用
* @author Rob Harrop
* @author Juergen Hoeller
* @since 2.0
Expand All @@ -42,12 +42,15 @@ public abstract class Conventions {

/**
* Suffix added to names when using arrays.
* 后缀添加到名字,当使用list时
*/
private static final String PLURAL_SUFFIX = "List";

/**
* Set of interfaces that are supposed to be ignored
* when searching for the 'primary' interface of a proxy.
*
* 应该被忽略的接口的集合,当查询代理的主要接口
*/
private static final Set<Class<?>> IGNORED_INTERFACES;
static {
Expand All @@ -72,6 +75,7 @@ public abstract class Conventions {
* For {@code Collection}s we attempt to 'peek ahead' in the
* {@code Collection} to determine the component type and
* return the pluralized version of that component type.
* <p>
* @param value the value to generate a variable name for
* @return the generated variable name
*/
Expand Down Expand Up @@ -104,6 +108,7 @@ else if (value instanceof Collection) {
/**
* Determine the conventional variable name for the supplied parameter,
* taking the generic collection type (if any) into account.
* <p> 决定conventional 变量名给根据提供的参数,将通用的集合类型给account
* @param parameter the method or constructor parameter to generate a variable name for
* @return the generated variable name
*/
Expand Down Expand Up @@ -135,6 +140,7 @@ else if (Collection.class.isAssignableFrom(parameter.getParameterType())) {
/**
* Determine the conventional variable name for the return type of the supplied method,
* taking the generic collection type (if any) into account.
* <p> 决定conventional 变量名给根据提供的方法返回类型,将通用的集合类型给account
* @param method the method to generate a variable name for
* @return the generated variable name
*/
Expand All @@ -147,6 +153,8 @@ public static String getVariableNameForReturnType(Method method) {
* taking the generic collection type (if any) into account, falling back to the
* given return value if the method declaration is not specific enough (i.e. in case of
* the return type being declared as {@code Object} or as untyped collection).
*
* <p> 决定conventional 变量名给根据提供的方法返回类型,将通用的集合类型给account
* @param method the method to generate a variable name for
* @param value the return value (may be {@code null} if not available)
* @return the generated variable name
Expand All @@ -160,6 +168,7 @@ public static String getVariableNameForReturnType(Method method, Object value) {
* taking the generic collection type (if any) into account, falling back to the
* given return value if the method declaration is not specific enough (i.e. in case of
* the return type being declared as {@code Object} or as untyped collection).
* <p> 决定conventional 变量名给根据提供的方法返回类型,将通用的集合类型给account
* @param method the method to generate a variable name for
* @param resolvedType the resolved return type of the method
* @param value the return value (may be {@code null} if not available)
Expand Down Expand Up @@ -211,6 +220,7 @@ else if (Collection.class.isAssignableFrom(resolvedType)) {
* Convert {@code String}s in attribute name format (lowercase, hyphens separating words)
* into property name format (camel-cased). For example, {@code transaction-manager} is
* converted into {@code transactionManager}.
* 转换attribute名称到属性名称,去掉-
*/
public static String attributeNameToPropertyName(String attributeName) {
Assert.notNull(attributeName, "'attributeName' must not be null");
Expand Down Expand Up @@ -240,6 +250,7 @@ else if (upperCaseNext) {
* Return an attribute name qualified by the supplied enclosing {@link Class}. For example,
* the attribute name '{@code foo}' qualified by {@link Class} '{@code com.myapp.SomeClass}'
* would be '{@code com.myapp.SomeClass.foo}'
* <p>根据给定的类和属性名,拼接为一个字符串
*/
public static String getQualifiedAttributeName(Class<?> enclosingClass, String attributeName) {
Assert.notNull(enclosingClass, "'enclosingClass' must not be null");
Expand All @@ -254,6 +265,8 @@ public static String getQualifiedAttributeName(Class<?> enclosingClass, String a
* <p>Will return the class of the given value, except when
* encountering a JDK proxy, in which case it will determine
* the 'primary' interface implemented by that proxy.
* <p>
* <p>返回给定类的类名,当为代理类是,返回代理类的第一接口
* @param value the value to check
* @return the class to use for naming a variable
*/
Expand All @@ -277,6 +290,7 @@ else if (valueClass.getName().lastIndexOf('$') != -1 && valueClass.getDeclaringC

/**
* Pluralize the given name.
* 多元化给定的name
*/
private static String pluralize(String name) {
return name + PLURAL_SUFFIX;
Expand All @@ -286,6 +300,7 @@ private static String pluralize(String name) {
* Retrieves the {@code Class} of an element in the {@code Collection}.
* The exact element for which the {@code Class} is retreived will depend
* on the concrete {@code Collection} implementation.
* <p>检索给定类的元素在集合中,返回第一个元素,类的其他元素依赖于concrete的集合实现
*/
private static <E> E peekAhead(Collection<E> collection) {
Iterator<E> it = collection.iterator();
Expand Down
Loading