Polish ReflectionHints and TypeHint method order
This commit is contained in:
@@ -125,6 +125,16 @@ public class ReflectionHints {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Field},
|
||||
* enabling write access.
|
||||
* @param field the field that requires reflection
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerField(Field field) {
|
||||
return registerField(field, fieldHint -> fieldHint.allowWrite(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Field}.
|
||||
* @param field the field that requires reflection
|
||||
@@ -136,14 +146,26 @@ public class ReflectionHints {
|
||||
typeHint -> typeHint.withField(field.getName(), fieldHint));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Field},
|
||||
* enabling write access.
|
||||
* @param field the field that requires reflection
|
||||
* Register the need for reflection on the specified {@link Constructor},
|
||||
* enabling {@link ExecutableMode#INVOKE}.
|
||||
* @param constructor the constructor that requires reflection
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerField(Field field) {
|
||||
return registerField(field, fieldHint -> fieldHint.allowWrite(true));
|
||||
public ReflectionHints registerConstructor(Constructor<?> constructor) {
|
||||
return registerConstructor(constructor, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Constructor},
|
||||
* using the specified {@link ExecutableMode}.
|
||||
* @param constructor the constructor that requires reflection
|
||||
* @param mode the requested mode
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerConstructor(Constructor<?> constructor, ExecutableMode mode) {
|
||||
return registerConstructor(constructor, constructorHint -> constructorHint.withMode(mode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,35 +181,13 @@ public class ReflectionHints {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Constructor},
|
||||
* using the specified {@link ExecutableMode}.
|
||||
* @param constructor the constructor that requires reflection
|
||||
* @param mode the requested mode
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerConstructor(Constructor<?> constructor, ExecutableMode mode) {
|
||||
return registerConstructor(constructor, constructorHint -> constructorHint.withMode(mode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Constructor},
|
||||
* Register the need for reflection on the specified {@link Method},
|
||||
* enabling {@link ExecutableMode#INVOKE}.
|
||||
* @param constructor the constructor that requires reflection
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public ReflectionHints registerConstructor(Constructor<?> constructor) {
|
||||
return registerConstructor(constructor, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Method}.
|
||||
* @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
|
||||
*/
|
||||
public ReflectionHints registerMethod(Method method, Consumer<ExecutableHint.Builder> methodHint) {
|
||||
return registerType(TypeReference.of(method.getDeclaringClass()),
|
||||
typeHint -> typeHint.withMethod(method.getName(), mapParameters(method), methodHint));
|
||||
public ReflectionHints registerMethod(Method method) {
|
||||
return registerMethod(method, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,13 +202,14 @@ public class ReflectionHints {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the specified {@link Method},
|
||||
* enabling {@link ExecutableMode#INVOKE}.
|
||||
* Register the need for reflection on the specified {@link Method}.
|
||||
* @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
|
||||
*/
|
||||
public ReflectionHints registerMethod(Method method) {
|
||||
return registerMethod(method, ExecutableMode.INVOKE);
|
||||
public ReflectionHints registerMethod(Method method, Consumer<ExecutableHint.Builder> methodHint) {
|
||||
return registerType(TypeReference.of(method.getDeclaringClass()),
|
||||
typeHint -> typeHint.withMethod(method.getName(), mapParameters(method), methodHint));
|
||||
}
|
||||
|
||||
private List<TypeReference> mapParameters(Executable executable) {
|
||||
|
||||
@@ -173,6 +173,16 @@ public final class TypeHint implements ConditionalHint {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the field with the specified name,
|
||||
* enabling write access.
|
||||
* @param name the name of the field
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withField(String name) {
|
||||
return withField(name, fieldHint -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the field with the specified name.
|
||||
* @param name the name of the field
|
||||
@@ -186,13 +196,24 @@ public final class TypeHint implements ConditionalHint {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the field with the specified name,
|
||||
* enabling write access.
|
||||
* @param name the name of the field
|
||||
* Register the need for reflection on the constructor with the specified
|
||||
* parameter types, enabling {@link ExecutableMode#INVOKE}.
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withField(String name) {
|
||||
return withField(name, fieldHint -> {});
|
||||
public Builder withConstructor(List<TypeReference> parameterTypes) {
|
||||
return withConstructor(parameterTypes, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the constructor with the specified
|
||||
* parameter types, using the specified {@link ExecutableMode}.
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @param mode the requested mode
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withConstructor(List<TypeReference> parameterTypes, ExecutableMode mode) {
|
||||
return withConstructor(parameterTypes, constructorHint -> constructorHint.withMode(mode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,41 +232,15 @@ public final class TypeHint implements ConditionalHint {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the constructor with the specified
|
||||
* parameter types, using the specified {@link ExecutableMode}.
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @param mode the requested mode
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withConstructor(List<TypeReference> parameterTypes, ExecutableMode mode) {
|
||||
return withConstructor(parameterTypes, constructorHint -> constructorHint.withMode(mode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the constructor with the specified
|
||||
* parameter types, enabling {@link ExecutableMode#INVOKE}.
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withConstructor(List<TypeReference> parameterTypes) {
|
||||
return withConstructor(parameterTypes, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the method with the specified name
|
||||
* and parameter types.
|
||||
* and parameter types, enabling {@link ExecutableMode#INVOKE}.
|
||||
* @param name the name of the method
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @param methodHint a builder to further customize the hints of this method
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withMethod(String name, List<TypeReference> parameterTypes, Consumer<ExecutableHint.Builder> methodHint) {
|
||||
ExecutableKey key = new ExecutableKey(name, parameterTypes);
|
||||
ExecutableHint.Builder builder = this.methods.computeIfAbsent(key,
|
||||
k -> ExecutableHint.ofMethod(name, parameterTypes));
|
||||
methodHint.accept(builder);
|
||||
return this;
|
||||
public Builder withMethod(String name, List<TypeReference> parameterTypes) {
|
||||
return withMethod(name, parameterTypes, ExecutableMode.INVOKE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,13 +257,18 @@ public final class TypeHint implements ConditionalHint {
|
||||
|
||||
/**
|
||||
* Register the need for reflection on the method with the specified name
|
||||
* and parameter types, enabling {@link ExecutableMode#INVOKE}.
|
||||
* and parameter types.
|
||||
* @param name the name of the method
|
||||
* @param parameterTypes the parameter types of the constructor
|
||||
* @param methodHint a builder to further customize the hints of this method
|
||||
* @return {@code this}, to facilitate method chaining
|
||||
*/
|
||||
public Builder withMethod(String name, List<TypeReference> parameterTypes) {
|
||||
return withMethod(name, parameterTypes, ExecutableMode.INVOKE);
|
||||
public Builder withMethod(String name, List<TypeReference> parameterTypes, Consumer<ExecutableHint.Builder> methodHint) {
|
||||
ExecutableKey key = new ExecutableKey(name, parameterTypes);
|
||||
ExecutableHint.Builder builder = this.methods.computeIfAbsent(key,
|
||||
k -> ExecutableHint.ofMethod(name, parameterTypes));
|
||||
methodHint.accept(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user