/** * 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); }
/** * Adds a post construct method definition. * * @param declaringType The declaring type * @param method The method * @param arguments The arguments * @param annotationMetadata The annotation metadata * @param requiresReflection Whether the method requires reflection * @return This bean definition */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition addPostConstruct(Class declaringType, String method, @Nullable Argument[] arguments, @Nullable AnnotationMetadata annotationMetadata, boolean requiresReflection) { return addInjectionPointInternal(declaringType, method, arguments, annotationMetadata, requiresReflection, this.postConstructMethods); }
/** * 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); }
/** * Adds a post construct method definition. * * @param declaringType The declaring type * @param method The method * @param arguments The arguments * @param annotationMetadata The annotation metadata * @param requiresReflection Whether the method requires reflection * @return This bean definition */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition addPostConstruct(Class declaringType, String method, @Nullable Argument[] arguments, @Nullable AnnotationMetadata annotationMetadata, boolean requiresReflection) { return addInjectionPointInternal(declaringType, method, arguments, annotationMetadata, requiresReflection, this.postConstructMethods); }
/** * Adds an injection point for a method that cannot be resolved at runtime, but a compile time produced injection * point exists. This allows the framework to recover and relay better error messages to the user instead of just * NoSuchMethodError. * * @param declaringType The declaring type * @param method The method * @param arguments The argument types * @param annotationMetadata The annotation metadata * @param requiresReflection Whether the method requires reflection to invoke * @return this component definition */ @SuppressWarnings({"unchecked", "unused"}) @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition addInjectionPoint( Class declaringType, String method, @Nullable Argument[] arguments, @Nullable AnnotationMetadata annotationMetadata, boolean requiresReflection) { return addInjectionPointInternal( declaringType, method, arguments, annotationMetadata, requiresReflection, this.methodInjectionPoints ); }
/** * Adds a pre destroy method definition. * * @param declaringType The declaring type * @param method The method * @param arguments The arguments * @param annotationMetadata The annotation metadata * @param requiresReflection Whether the method requires reflection * @return This bean definition */ @SuppressWarnings("unused") @Internal @UsedByGeneratedCode protected final AbstractBeanDefinition addPreDestroy(Class declaringType, String method, Argument[] arguments, AnnotationMetadata annotationMetadata, boolean requiresReflection) { return addInjectionPointInternal(declaringType, method, arguments, annotationMetadata, requiresReflection, this.preDestroyMethods); }