/** * Create a {@link LinkedHashMap} from an array of values. * * @param values The values * @return The created map */ @UsedByGeneratedCode public static Map mapOf(Object... values) { int len = values.length; if (len % 2 != 0) { throw new IllegalArgumentException("Number of arguments should be an even number representing the keys and values"); } Map answer = new LinkedHashMap(len / 2); int i = 0; while (i < values.length - 1) { answer.put(values[i++], values[i++]); } return answer; }
/** * Creates a new argument for the given type and name. * * @param type The type * @param name The name * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of( Class<T> type, String name) { return new DefaultArgument<>(type, name, AnnotationMetadata.EMPTY_METADATA, Argument.ZERO_ARGUMENTS); }
/** * Creates a new argument for the given type and name. * * @param type The type * @param name The name * @param typeParameters the type parameters * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of( Class<T> type, String name, @Nullable Argument... typeParameters) { return new DefaultArgument<>(type, name, AnnotationMetadata.EMPTY_METADATA, typeParameters); }
/** * Creates a new argument for the given type and name. * * @param type The type * @param name The name * @param annotationMetadata the annotation metadata * @param typeParameters the type parameters * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of( Class<T> type, String name, AnnotationMetadata annotationMetadata, @Nullable Argument... typeParameters) { return new DefaultArgument<>(type, name, annotationMetadata, typeParameters); }
/** * Creates a new argument for the given type and name. * * @param type The type * @param typeParameters The parameters type * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of( Class<T> type, @Nullable Argument... typeParameters) { return new DefaultArgument<>(type, NameUtils.decapitalize(type.getSimpleName()), AnnotationMetadata.EMPTY_METADATA, typeParameters); }
/** * Creates a new argument for the given type and name. * * @param type The type * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of( Class<T> type) { return new DefaultArgument<>(type, NameUtils.decapitalize(type.getSimpleName()), AnnotationMetadata.EMPTY_METADATA, Argument.ZERO_ARGUMENTS); }
/** * Creates a new argument for the given type and name. * * @param type The type * @param typeParameters the parameters type * @param <T> The generic type * @return The argument instance */ @UsedByGeneratedCode static <T> Argument<T> of(Class<T> type, @Nullable Class<?>... typeParameters) { if (typeParameters == null) { return of(type); } TypeVariable<Class<T>>[] parameters = type.getTypeParameters(); int len = typeParameters.length; if (parameters.length != len) { throw new IllegalArgumentException("Type parameter length does not match. Required: " + parameters.length + ", Specified: " + len); } Argument[] typeArguments = new Argument[len]; for (int i = 0; i < parameters.length; i++) { TypeVariable<Class<T>> parameter = parameters[i]; typeArguments[i] = Argument.of(typeParameters[i], parameter.getName()); } return new DefaultArgument<>(type, NameUtils.decapitalize(type.getSimpleName()), AnnotationMetadata.EMPTY_METADATA, typeArguments); }
/** * @param instance The instance * @param arguments The arguments * @return The result */ @SuppressWarnings("WeakerAccess") @UsedByGeneratedCode protected abstract Object invokeInternal(Object instance, Object[] arguments);
/** * @param instance The instance * @param arguments The arguments * @return The result */ @SuppressWarnings("WeakerAccess") @UsedByGeneratedCode protected abstract Object invokeInternal(Object instance, Object[] arguments);
/** * Get a bean of the given type. * * @param resolutionContext The bean context resolution * @param beanType The bean type * @param <T> The bean type parameter * @return The found bean */ @UsedByGeneratedCode public <T> T getBean(BeanResolutionContext resolutionContext, Class<T> beanType) { return getBeanInternal(resolutionContext, beanType, null, true, true); }
/** * Get a bean of the given type. * * @param resolutionContext The bean context resolution * @param beanType The bean type * @param <T> The bean type parameter * @return The found bean */ @UsedByGeneratedCode public <T> T getBean(BeanResolutionContext resolutionContext, Class<T> beanType) { return getBeanInternal(resolutionContext, beanType, null, true, true); }
/** * The default implementation which provides no injection. To be overridden by compile time tooling. * * @param resolutionContext The resolution context * @param context The bean context * @param bean The bean * @return The injected bean */ @Internal @SuppressWarnings({"WeakerAccess", "unused"}) @UsedByGeneratedCode protected Object injectBean(BeanResolutionContext resolutionContext, BeanContext context, Object bean) { return bean; }
/** * The default implementation which provides no injection. To be overridden by compile time tooling. * * @param resolutionContext The resolution context * @param context The bean context * @param bean The bean * @return The injected bean */ @Internal @SuppressWarnings({"WeakerAccess", "unused"}) @UsedByGeneratedCode protected Object injectBean(BeanResolutionContext resolutionContext, BeanContext context, Object bean) { return bean; }
/** * Obtains a bean definition for the field at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param fieldIndex The field index * @return The resolved bean */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final Object getBeanForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex) { FieldInjectionPoint injectionPoint = fieldInjectionPoints.get(fieldIndex); return getBeanForField(resolutionContext, context, injectionPoint); }
/** * If this bean is a {@link ConfigurationProperties} bean return whether any properties for it are configured * within the context. * * @param resolutionContext the resolution context * @param context The context * @return True if it does */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final boolean containsProperties(BeanResolutionContext resolutionContext, BeanContext context) { return containsProperties(resolutionContext, context, null); }
/** * If this bean is a {@link ConfigurationProperties} bean return whether any properties for it are configured * within the context. * * @param resolutionContext the resolution context * @param context The context * @return True if it does */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final boolean containsProperties(BeanResolutionContext resolutionContext, BeanContext context) { return containsProperties(resolutionContext, context, null); }
/** * Obtains a bean definition for the field at the given index and the argument at the given index * <p> * Warning: this method is used by internal generated code and should not be called by user code. * * @param resolutionContext The resolution context * @param context The context * @param fieldIndex The field index * @return The resolved bean */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final Object getBeanForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex) { FieldInjectionPoint injectionPoint = fieldInjectionPoints.get(fieldIndex); instrumentAnnotationMetadata(context, injectionPoint); return getBeanForField(resolutionContext, context, injectionPoint); }
/** * Adds a new {@link ExecutableMethod}. * * @param executableMethod The method * @return The bean definition */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition<T> addExecutableMethod(ExecutableMethod<T, ?> executableMethod) { MethodKey key = new MethodKey(executableMethod.getMethodName(), executableMethod.getArgumentTypes()); executableMethodMap.put(key, executableMethod); return this; }
/** * Adds a new {@link ExecutableMethod}. * * @param executableMethod The method * @return The bean definition */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition<T> addExecutableMethod(ExecutableMethod<T, ?> executableMethod) { MethodKey key = new MethodKey(executableMethod.getMethodName(), executableMethod.getArgumentTypes()); executableMethodMap.put(key, executableMethod); return this; }
/** * Inject another bean, for example one created via factory. * * @param resolutionContext The reslution context * @param context The context * @param bean The bean * @return The bean */ @Internal @SuppressWarnings({"WeakerAccess", "unused"}) @UsedByGeneratedCode protected Object injectAnother(BeanResolutionContext resolutionContext, BeanContext context, Object bean) { DefaultBeanContext defaultContext = (DefaultBeanContext) context; if (bean == null) { throw new BeanInstantiationException(resolutionContext, "Bean factory returned null"); } return defaultContext.inject(resolutionContext, this, bean); }