public class ConstructorInstantiator extends java.lang.Object implements Instantiator
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
constructorArgs |
private boolean |
hasOuterClassInstance
Whether or not the constructors used for creating an object refer to an outer instance or not.
|
Constructor and Description |
---|
ConstructorInstantiator(boolean hasOuterClassInstance,
java.lang.Object... constructorArgs) |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
constructorArgsString() |
private java.lang.String |
constructorArgTypes() |
private void |
evaluateConstructor(java.util.List<java.lang.reflect.Constructor<?>> matchingConstructors,
java.lang.reflect.Constructor<?> constructor)
Evalutes
constructor against the currently found matchingConstructors and determines if
it's a better match to the given arguments, a worse match, or an equivalently good match. |
private static <T> T |
invokeConstructor(java.lang.reflect.Constructor<?> constructor,
java.lang.Object... params) |
private InstantiationException |
multipleMatchingConstructors(java.lang.Class<?> cls,
java.util.List<java.lang.reflect.Constructor<?>> constructors) |
<T> T |
newInstance(java.lang.Class<T> cls)
Creates instance of given class
|
private InstantiationException |
noMatchingConstructor(java.lang.Class<?> cls) |
private InstantiationException |
paramsException(java.lang.Class<?> cls,
java.lang.Exception e) |
private static boolean |
paramsMatch(java.lang.Class<?>[] types,
java.lang.Object[] params) |
private <T> T |
withParams(java.lang.Class<T> cls,
java.lang.Object... params) |
private final boolean hasOuterClassInstance
constructorArgs
array.private final java.lang.Object[] constructorArgs
public ConstructorInstantiator(boolean hasOuterClassInstance, java.lang.Object... constructorArgs)
public <T> T newInstance(java.lang.Class<T> cls)
Instantiator
newInstance
in interface Instantiator
private <T> T withParams(java.lang.Class<T> cls, java.lang.Object... params)
private static <T> T invokeConstructor(java.lang.reflect.Constructor<?> constructor, java.lang.Object... params) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
private InstantiationException paramsException(java.lang.Class<?> cls, java.lang.Exception e)
private java.lang.String constructorArgTypes()
private InstantiationException noMatchingConstructor(java.lang.Class<?> cls)
private java.lang.String constructorArgsString()
private InstantiationException multipleMatchingConstructors(java.lang.Class<?> cls, java.util.List<java.lang.reflect.Constructor<?>> constructors)
private static boolean paramsMatch(java.lang.Class<?>[] types, java.lang.Object[] params)
private void evaluateConstructor(java.util.List<java.lang.reflect.Constructor<?>> matchingConstructors, java.lang.reflect.Constructor<?> constructor)
constructor
against the currently found matchingConstructors
and determines if
it's a better match to the given arguments, a worse match, or an equivalently good match.
This method tries to emulate the behavior specified in JLS 15.12.2. Compile-Time Step 2: Determine Method Signature. A constructor X is deemed to be a better match than constructor Y to the given argument list if they are both applicable, constructor X has at least one parameter than is more specific than the corresponding parameter of constructor Y, and constructor Y has no parameter than is more specific than the corresponding parameter in constructor X.
If constructor
is a better match than the constructors in the matchingConstructors
list, the list
is cleared, and it's added to the list as a singular best matching constructor (so far).
If constructor
is an equivalently good of a match as the constructors in the matchingConstructors
list, it's added to the list.
If constructor
is a worse match than the constructors in the matchingConstructors
list, the list
will remain unchanged.
matchingConstructors
- A list of equivalently best matching constructors found so farconstructor
- The constructor to be evaluated against this list