2121import  java .util .Map ;
2222import  java .util .Optional ;
2323import  java .util .Set ;
24+ import  java .util .function .Function ;
2425import  java .util .stream .Stream ;
2526
2627import  org .springframework .beans .factory .support .BeanDefinitionRegistry ;
4243import  org .springframework .util .StringUtils ;
4344
4445/** 
45-  * Annotation  based {@link RepositoryConfigurationSource}. 
46+  * Annotation- based {@link RepositoryConfigurationSource}. 
4647 * 
4748 * @author Oliver Gierke 
4849 * @author Thomas Darimont 
@@ -67,9 +68,7 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
6768	private  final  AnnotationMetadata  configMetadata ;
6869	private  final  AnnotationMetadata  enableAnnotationMetadata ;
6970	private  final  AnnotationAttributes  attributes ;
70- 	private  final  ResourceLoader  resourceLoader ;
71- 	private  final  Environment  environment ;
72- 	private  final  BeanDefinitionRegistry  registry ;
71+ 	private  final  Function <AnnotationAttributes , Stream <TypeFilter >> typeFilterFunction ;
7372	private  final  boolean  hasExplicitFilters ;
7473
7574	/** 
@@ -83,7 +82,7 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
8382	 * @param registry must not be {@literal null}. 
8483	 * @deprecated since 2.2. Prefer to use overload taking a {@link BeanNameGenerator} additionally. 
8584	 */ 
86- 	@ Deprecated 
85+ 	@ Deprecated ( since  =  "2.2" ) 
8786	public  AnnotationRepositoryConfigurationSource (AnnotationMetadata  metadata , Class <? extends  Annotation > annotation ,
8887			ResourceLoader  resourceLoader , Environment  environment , BeanDefinitionRegistry  registry ) {
8988		this (metadata , annotation , resourceLoader , environment , registry , null );
@@ -120,12 +119,12 @@ public AnnotationRepositoryConfigurationSource(AnnotationMetadata metadata, Clas
120119		this .attributes  = new  AnnotationAttributes (annotationAttributes );
121120		this .enableAnnotationMetadata  = AnnotationMetadata .introspect (annotation );
122121		this .configMetadata  = metadata ;
123- 		this .resourceLoader  = resourceLoader ;
124- 		this .environment  = environment ;
125- 		this .registry  = registry ;
122+ 		this .typeFilterFunction  = it  -> TypeFilterUtils .createTypeFiltersFor (it , environment , resourceLoader , registry )
123+ 				.stream ();
126124		this .hasExplicitFilters  = hasExplicitFilters (attributes );
127125	}
128126
127+ 	@ Override 
129128	public  Streamable <String > getBasePackages () {
130129
131130		String [] value  = attributes .getStringArray ("value" );
@@ -139,7 +138,7 @@ public Streamable<String> getBasePackages() {
139138			return  Streamable .of (ClassUtils .getPackageName (className ));
140139		}
141140
142- 		Set <String > packages  = new  HashSet <>();
141+ 		Set <String > packages  = new  HashSet <>(value . length  +  basePackages . length  +  basePackageClasses . length );
143142		packages .addAll (Arrays .asList (value ));
144143		packages .addAll (Arrays .asList (basePackages ));
145144
@@ -150,18 +149,22 @@ public Streamable<String> getBasePackages() {
150149		return  Streamable .of (packages );
151150	}
152151
152+ 	@ Override 
153153	public  Optional <Object > getQueryLookupStrategyKey () {
154154		return  Optional .ofNullable (attributes .get (QUERY_LOOKUP_STRATEGY ));
155155	}
156156
157+ 	@ Override 
157158	public  Optional <String > getNamedQueryLocation () {
158159		return  getNullDefaultedAttribute (NAMED_QUERIES_LOCATION );
159160	}
160161
162+ 	@ Override 
161163	public  Optional <String > getRepositoryImplementationPostfix () {
162164		return  getNullDefaultedAttribute (REPOSITORY_IMPLEMENTATION_POSTFIX );
163165	}
164166
167+ 	@ Override 
165168	@ NonNull 
166169	public  Object  getSource () {
167170		return  configMetadata ;
@@ -265,25 +268,22 @@ public BootstrapMode getBootstrapMode() {
265268	public  String  getResourceDescription () {
266269
267270		String  simpleClassName  = ClassUtils .getShortName (configMetadata .getClassName ());
268- 		String  annoationClassName  = ClassUtils .getShortName (enableAnnotationMetadata .getClassName ());
271+ 		String  annotationClassName  = ClassUtils .getShortName (enableAnnotationMetadata .getClassName ());
269272
270- 		return  String .format ("@%s declared on %s" , annoationClassName , simpleClassName );
273+ 		return  String .format ("@%s declared on %s" , annotationClassName , simpleClassName );
271274	}
272275
273276	private  Streamable <TypeFilter > parseFilters (String  attributeName ) {
274277
275278		AnnotationAttributes [] filters  = attributes .getAnnotationArray (attributeName );
276- 
277- 		return  Streamable .of (() -> Arrays .stream (filters ) // 
278- 				.flatMap (it  -> TypeFilterUtils .createTypeFiltersFor (it , this .environment , this .resourceLoader , this .registry )
279- 						.stream ()));
279+ 		return  Streamable .of (() -> Arrays .stream (filters ).flatMap (typeFilterFunction ));
280280	}
281281
282282	/** 
283283	 * Returns the {@link String} attribute with the given name and defaults it to {@literal Optional#empty()} in case 
284284	 * it's empty. 
285285	 * 
286- 	 * @param attributeName 
286+ 	 * @param attributeName must not be {@literal null}.  
287287	 * @return 
288288	 */ 
289289	private  Optional <String > getNullDefaultedAttribute (String  attributeName ) {
0 commit comments