@ -36,6 +36,8 @@ import org.springframework.util.ClassUtils;
@@ -36,6 +36,8 @@ import org.springframework.util.ClassUtils;
* Gather the need for reflection at runtime .
*
* @author Stephane Nicoll
* @author Phillip Webb
* @author Andy Wilkinson
* @since 6 . 0
* /
public class ReflectionHints {
@ -79,6 +81,7 @@ public class ReflectionHints {
@@ -79,6 +81,7 @@ public class ReflectionHints {
* @param type the type to customize
* @param typeHint a builder to further customize hints for that type
* @return { @code this } , to facilitate method chaining
* @see # registerType ( TypeReference , MemberCategory . . . )
* /
public ReflectionHints registerType ( TypeReference type , Consumer < TypeHint . Builder > typeHint ) {
Builder builder = this . types . computeIfAbsent ( type , TypeHint . Builder : : new ) ;
@ -93,29 +96,30 @@ public class ReflectionHints {
@@ -93,29 +96,30 @@ public class ReflectionHints {
* @param memberCategories the member categories to apply
* @return { @code this } , to facilitate method chaining
* /
public ReflectionHints registerType ( Class < ? > type , MemberCategory . . . memberCategories ) {
return registerType ( TypeReference . of ( type ) , memberCategories ) ;
public ReflectionHints registerType ( TypeReference type , MemberCategory . . . memberCategories ) {
return registerType ( type , TypeHint . builtWith ( memberCategories ) ) ;
}
/ * *
* Register or customize reflection hints for the specified type
* using the specified { @link MemberCategory MemberCategories } .
* Register or customize reflection hints for the specified type .
* @param type the type to customize
* @param memberCategories the member categories to apply
* @param typeHint a builder to further customize hints for that type
* @return { @code this } , to facilitate method chaining
* @see # registerType ( Class , MemberCategory . . . )
* /
public ReflectionHints registerType ( TypeReference type , MemberCategory . . . memberCategories ) {
return registerType ( type , TypeHint . builtWith ( memberCategories ) ) ;
public ReflectionHints registerType ( Class < ? > type , Consumer < TypeHint . Builder > typeHint ) {
return registerType ( TypeReference . of ( type ) , typeHint ) ;
}
/ * *
* Register or customize reflection hints for the specified type .
* Register or customize reflection hints for the specified type
* using the specified { @link MemberCategory MemberCategories } .
* @param type the type to customize
* @param typeHint a builder to further customize hints for that type
* @param memberCategories the member categories to apply
* @return { @code this } , to facilitate method chaining
* /
public ReflectionHints registerType ( Class < ? > type , Consumer < TypeHint . Builder > typeHint ) {
return registerType ( TypeReference . of ( type ) , typeHint ) ;
public ReflectionHints registerType ( Class < ? > type , MemberCategory . . . memberCategories ) {
return registerType ( TypeReference . of ( type ) , memberCategories ) ;
}
/ * *
@ -125,6 +129,7 @@ public class ReflectionHints {
@@ -125,6 +129,7 @@ public class ReflectionHints {
* @param typeName the type to customize
* @param typeHint a builder to further customize hints for that type
* @return { @code this } , to facilitate method chaining
* @see # registerTypeIfPresent ( ClassLoader , String , MemberCategory . . . )
* /
public ReflectionHints registerTypeIfPresent ( @Nullable ClassLoader classLoader ,
String typeName , Consumer < TypeHint . Builder > typeHint ) {
@ -134,6 +139,19 @@ public class ReflectionHints {
@@ -134,6 +139,19 @@ public class ReflectionHints {
return this ;
}
/ * *
* Register or customize reflection hints for the specified type if it
* is available using the specified { @link ClassLoader } .
* @param classLoader the classloader to use to check if the type is present
* @param typeName the type to customize
* @param memberCategories the member categories to apply
* @return { @code this } , to facilitate method chaining
* /
public ReflectionHints registerTypeIfPresent ( @Nullable ClassLoader classLoader ,
String typeName , MemberCategory . . . memberCategories ) {
return registerTypeIfPresent ( classLoader , typeName , TypeHint . builtWith ( memberCategories ) ) ;
}
/ * *
* Register or customize reflection hints for the types defined by the
* specified list of { @link TypeReference type references } . The specified
@ -162,7 +180,9 @@ public class ReflectionHints {
@@ -162,7 +180,9 @@ public class ReflectionHints {
* enabling { @link ExecutableMode # INVOKE } .
* @param constructor the constructor that requires reflection
* @return { @code this } , to facilitate method chaining
* @deprecated in favor of { @link # registerConstructor ( Constructor , ExecutableMode ) }
* /
@Deprecated
public ReflectionHints registerConstructor ( Constructor < ? > constructor ) {
return registerConstructor ( constructor , ExecutableMode . INVOKE ) ;
}
@ -175,7 +195,8 @@ public class ReflectionHints {
@@ -175,7 +195,8 @@ public class ReflectionHints {
* @return { @code this } , to facilitate method chaining
* /
public ReflectionHints registerConstructor ( Constructor < ? > constructor , ExecutableMode mode ) {
return registerConstructor ( constructor , ExecutableHint . builtWith ( mode ) ) ;
return registerType ( TypeReference . of ( constructor . getDeclaringClass ( ) ) ,
typeHint - > typeHint . withConstructor ( mapParameters ( constructor ) , mode ) ) ;
}
/ * *
@ -183,8 +204,10 @@ public class ReflectionHints {
@@ -183,8 +204,10 @@ public class ReflectionHints {
* @param constructor the constructor that requires reflection
* @param constructorHint a builder to further customize the hints of this
* constructor
* @return { @code this } , to facilitate method chaining
* @return { @code this } , to facilitate method chaining `
* @deprecated in favor of { @link # registerConstructor ( Constructor , ExecutableMode ) }
* /
@Deprecated
public ReflectionHints registerConstructor ( Constructor < ? > constructor , Consumer < ExecutableHint . Builder > constructorHint ) {
return registerType ( TypeReference . of ( constructor . getDeclaringClass ( ) ) ,
typeHint - > typeHint . withConstructor ( mapParameters ( constructor ) , constructorHint ) ) ;
@ -195,7 +218,9 @@ public class ReflectionHints {
@@ -195,7 +218,9 @@ public class ReflectionHints {
* enabling { @link ExecutableMode # INVOKE } .
* @param method the method that requires reflection
* @return { @code this } , to facilitate method chaining
* @deprecated in favor of { @link # registerMethod ( Method , ExecutableMode ) }
* /
@Deprecated
public ReflectionHints registerMethod ( Method method ) {
return registerMethod ( method , ExecutableMode . INVOKE ) ;
}
@ -208,7 +233,8 @@ public class ReflectionHints {
@@ -208,7 +233,8 @@ public class ReflectionHints {
* @return { @code this } , to facilitate method chaining
* /
public ReflectionHints registerMethod ( Method method , ExecutableMode mode ) {
return registerMethod ( method , ExecutableHint . builtWith ( mode ) ) ;
return registerType ( TypeReference . of ( method . getDeclaringClass ( ) ) ,
typeHint - > typeHint . withMethod ( method . getName ( ) , mapParameters ( method ) , mode ) ) ;
}
/ * *
@ -216,7 +242,9 @@ public class ReflectionHints {
@@ -216,7 +242,9 @@ public class ReflectionHints {
* @param method the method that requires reflection
* @param methodHint a builder to further customize the hints of this method
* @return { @code this } , to facilitate method chaining
* @deprecated in favor of { @link # registerMethod ( Method , ExecutableMode ) }
* /
@Deprecated
public ReflectionHints registerMethod ( Method method , Consumer < ExecutableHint . Builder > methodHint ) {
return registerType ( TypeReference . of ( method . getDeclaringClass ( ) ) ,
typeHint - > typeHint . withMethod ( method . getName ( ) , mapParameters ( method ) , methodHint ) ) ;