/** * Get argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param requiredType the type to match (can be {@code null} to match * untyped values only) * @return the ValueHolder for the argument, or {@code null} if none set */ @Nullable public ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType) { return getIndexedArgumentValue(index, requiredType, null); }
/** * Get argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param requiredType the type to match (can be {@code null} to match * untyped values only) * @return the ValueHolder for the argument, or {@code null} if none set */ @Nullable public ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType) { return getIndexedArgumentValue(index, requiredType, null); }
/** * Look for an argument value that either corresponds to the given index * in the constructor argument list or generically matches by type. * @param index the index in the constructor argument list * @param requiredType the parameter type to match (can be {@code null} * to find an untyped argument value) * @param requiredName the parameter name to match (can be {@code null} * to find an unnamed argument value, or empty String to match any name) * @param usedValueHolders a Set of ValueHolder objects that have already * been used in the current resolution process and should therefore not * be returned again (allowing to return the next generic argument match * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or {@code null} if none set */ @Nullable public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { valueHolder = getGenericArgumentValue(requiredType, requiredName, usedValueHolders); } return valueHolder; }
/** * Look for an argument value that either corresponds to the given index * in the constructor argument list or generically matches by type. * @param index the index in the constructor argument list * @param requiredType the parameter type to match (can be {@code null} * to find an untyped argument value) * @param requiredName the parameter name to match (can be {@code null} * to find an unnamed argument value, or empty String to match any name) * @param usedValueHolders a Set of ValueHolder objects that have already * been used in the current resolution process and should therefore not * be returned again (allowing to return the next generic argument match * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or {@code null} if none set */ @Nullable public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { valueHolder = getGenericArgumentValue(requiredType, requiredName, usedValueHolders); } return valueHolder; }
/** * Register the processor with a {@link BeanDefinitionRegistry}. Not required when * using the Spocks {@link spock.lang.Specification} as registration is automatic. * * @param registry the bean definition registry * @param postProcessor the post processor class to register * @param definitions the initial mock/spy definitions */ @SuppressWarnings("unchecked") static void register(BeanDefinitionRegistry registry, Class<? extends SpockMockPostprocessor> postProcessor, Set<Definition> definitions) { SpyPostProcessor.register(registry); BeanDefinition definition = getOrAddBeanDefinition(registry, postProcessor); ValueHolder constructorArg = definition.getConstructorArgumentValues().getIndexedArgumentValue(0, Set.class); Set<Definition> existing = (Set<Definition>)constructorArg.getValue(); if (definitions != null) { existing.addAll(definitions); } }
private static StaticScriptSource getScriptSource(GenericApplicationContext ctx) throws Exception { ScriptFactoryPostProcessor processor = (ScriptFactoryPostProcessor) ctx.getBean(PROCESSOR_BEAN_NAME); BeanDefinition bd = processor.scriptBeanFactory.getBeanDefinition("scriptedObject.messenger"); return (StaticScriptSource) bd.getConstructorArgumentValues().getIndexedArgumentValue(0, StaticScriptSource.class).getValue(); }
/** * Get argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param requiredType the type to match (can be <code>null</code> to match * untyped values only) * @return the ValueHolder for the argument, or <code>null</code> if none set */ public ValueHolder getIndexedArgumentValue(int index, Class requiredType) { return getIndexedArgumentValue(index, requiredType, null); }
/** * Look for an argument value that either corresponds to the given index * in the constructor argument list or generically matches by type. * @param index the index in the constructor argument list * @param requiredType the type to match (can be <code>null</code> to find * an untyped argument value) * @param usedValueHolders a Set of ValueHolder objects that have already * been used in the current resolution process and should therefore not * be returned again (allowing to return the next generic argument match * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or <code>null</code> if none set */ public ValueHolder getArgumentValue(int index, Class requiredType, String requiredName, Set<ValueHolder> usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { valueHolder = getGenericArgumentValue(requiredType, requiredName, usedValueHolders); } return valueHolder; }
@SuppressWarnings("unchecked") private void collectPatternsFromInterceptor(Map<String, Set<String>> securityInterceptors, String beanName, BeanDefinition beanDefinition) { ConstructorArgumentValues.ValueHolder metadataSourceValueHolder = beanDefinition .getConstructorArgumentValues() .getIndexedArgumentValue(0, BeanDefinition.class); if (metadataSourceValueHolder != null) { BeanDefinition metadataSource = (BeanDefinition) metadataSourceValueHolder.getValue(); if (metadataSource != null) { ConstructorArgumentValues.ValueHolder patternMappingsValueHolder = metadataSource .getConstructorArgumentValues() .getIndexedArgumentValue(0, Map.class); if (patternMappingsValueHolder != null) { Map<String, ?> patternsToAdd = (Map<String, ?>) patternMappingsValueHolder.getValue(); Set<String> patterns = new ManagedSet<>(); if (!securityInterceptors.containsKey(beanName)) { securityInterceptors.put(beanName, patterns); } else { patterns = securityInterceptors.get(beanName); } if (patternsToAdd != null) { patterns.addAll(patternsToAdd.keySet()); } } } } }
/** * Get argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param requiredType the type to match (can be {@code null} to match * untyped values only) * @return the ValueHolder for the argument, or {@code null} if none set */ public ValueHolder getIndexedArgumentValue(int index, Class<?> requiredType) { return getIndexedArgumentValue(index, requiredType, null); }
/** * Look for an argument value that either corresponds to the given index * in the constructor argument list or generically matches by type. * @param index the index in the constructor argument list * @param requiredType the type to match * @param usedValueHolders a Set of ValueHolder objects that have already * been used in the current resolution process and should therefore not * be returned again (allowing to return the next generic argument match * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or <code>null</code> if none set */ public ValueHolder getArgumentValue(int index, Class requiredType, Set usedValueHolders) { ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType); if (valueHolder == null) { valueHolder = getGenericArgumentValue(requiredType, usedValueHolders); } return valueHolder; }
/** * Look for an argument value that either corresponds to the given index * in the constructor argument list or generically matches by type. * @param index the index in the constructor argument list * @param requiredType the parameter type to match (can be {@code null} * to find an untyped argument value) * @param requiredName the parameter name to match (can be {@code null} * to find an unnamed argument value, or empty String to match any name) * @param usedValueHolders a Set of ValueHolder objects that have already * been used in the current resolution process and should therefore not * be returned again (allowing to return the next generic argument match * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or {@code null} if none set */ public ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName, Set<ValueHolder> usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { valueHolder = getGenericArgumentValue(requiredType, requiredName, usedValueHolders); } return valueHolder; }
private String getLoginFormUrl(BeanDefinition entryPoint) { if (entryPoint == null) { return null; } ConstructorArgumentValues cavs = entryPoint.getConstructorArgumentValues(); ValueHolder vh = cavs.getIndexedArgumentValue(0, String.class); if (vh == null) { return null; } // If the login URL is the default one, then it is assumed not to have been set explicitly if (DefaultLoginPageGeneratingFilter.DEFAULT_LOGIN_PAGE_URL.equals(vh.getValue())) { return null; } return (String) vh.getValue(); }
if (!ArrayList.class.getName().equals(groupDef.getBeanClassName()) || constructorArgumentValues.getArgumentCount() != 1 || constructorArgumentValues.getIndexedArgumentValue(0, ManagedList.class) == null) { parserContext.getReaderContext().error("Unexpected configuration for bean " + group, element); .getIndexedArgumentValue(0, ManagedList.class).getValue(); // NOSONAR never null
if (!ArrayList.class.getName().equals(groupDef.getBeanClassName()) || constructorArgumentValues.getArgumentCount() != 1 || constructorArgumentValues.getIndexedArgumentValue(0, ManagedList.class) == null) { parserContext.getReaderContext().error("Unexpected configuration for bean " + group, element); .getIndexedArgumentValue(0, ManagedList.class).getValue(); // NOSONAR never null
/** * Register the processor with a {@link BeanDefinitionRegistry}. Not required when * using the {@link SpringRunner} as registration is automatic. * @param registry the bean definition registry * @param postProcessor the post processor class to register * @param definitions the initial mock/spy definitions */ @SuppressWarnings("unchecked") public static void register(BeanDefinitionRegistry registry, Class<? extends MockitoPostProcessor> postProcessor, Set<Definition> definitions) { SpyPostProcessor.register(registry); BeanDefinition definition = getOrAddBeanDefinition(registry, postProcessor); ValueHolder constructorArg = definition.getConstructorArgumentValues() .getIndexedArgumentValue(0, Set.class); Set<Definition> existing = (Set<Definition>) constructorArg.getValue(); if (definitions != null) { existing.addAll(definitions); } }
@Override public void registerBeanDefinitions( AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry ) { if ( !registry.containsBeanDefinition( BEAN ) ) { AutoConfigurationPackages.register( registry ); } BeanDefinition beanDefinition = registry.getBeanDefinition( BEAN ); ConstructorArgumentValues constructorArguments = beanDefinition.getConstructorArgumentValues(); String[] existing = (String[]) constructorArguments.getIndexedArgumentValue( 0, String[].class ).getValue(); if ( existing.length > 0 ) { applicationModulePackage = existing[0] + ".application"; LOG.info( "Disabling @AutoConfigurationPackage on the root package - Across applications support only the application module" ); constructorArguments.addIndexedArgumentValue( 0, new String[0] ); AcrossDynamicModulesConfiguration.verifyNoConflictingComponentScans( importingClassMetadata, existing[0] ); } if ( registry instanceof BeanFactory ) { LOG.trace( "Eager instantiation of AutoConfigurationPackages singleton" ); AutoConfigurationPackages.get( (BeanFactory) registry ); } SingletonBeanRegistry singletonBeanRegistry = (SingletonBeanRegistry) registry; if ( !singletonBeanRegistry.containsSingleton( ApplicationAutoConfigurationPackage.class.getName() ) ) { singletonBeanRegistry.registerSingleton( ApplicationAutoConfigurationPackage.class.getName(), this ); } } }