Skip to content

Commit 3fc2cb9

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Refine naming. See: #3267 Original Pull Request: #3367
1 parent 87565ae commit 3fc2cb9

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private ManagedTypes resolveManagedTypes(RegisteredBean registeredBean) {
119119

120120
/**
121121
* Hook to provide a customized flavor of {@link BeanRegistrationAotContribution}. By overriding this method calls to
122-
* {@link #contributeType(ResolvableType, GenerationContext, AotContext)} might no longer be issued.
122+
* {@link #registerTypeHints(ResolvableType, AotContext, GenerationContext)} might no longer be issued.
123123
*
124124
* @param aotContext never {@literal null}.
125125
* @param managedTypes never {@literal null}.
@@ -128,7 +128,7 @@ private ManagedTypes resolveManagedTypes(RegisteredBean registeredBean) {
128128
protected BeanRegistrationAotContribution contribute(AotContext aotContext, ManagedTypes managedTypes,
129129
RegisteredBean registeredBean) {
130130
return new ManagedTypesRegistrationAotContribution(aotContext, managedTypes, registeredBean,
131-
typeCollectorCustomizer(), this::contributeType);
131+
typeCollectorCustomizer(), this::registerTypeHints);
132132
}
133133

134134
/**
@@ -140,22 +140,22 @@ protected BeanRegistrationAotContribution contribute(AotContext aotContext, Mana
140140
protected Consumer<TypeCollector> typeCollectorCustomizer() {
141141
return typeCollector -> {};
142142
}
143+
143144
/**
144145
* Hook to contribute configuration for a given {@literal type}.
145146
*
146147
* @param type never {@literal null}.
147148
* @param generationContext never {@literal null}.
148149
*/
149-
protected void contributeType(ResolvableType type, GenerationContext generationContext, AotContext aotContext) {
150+
protected void registerTypeHints(ResolvableType type, AotContext aotContext, GenerationContext generationContext) {
150151

151152
if (logger.isDebugEnabled()) {
152153
logger.debug(String.format("Contributing type information for [%s]", type.getType()));
153154
}
154155

155156
Set<String> annotationNamespaces = Collections.singleton(TypeContributor.DATA_NAMESPACE);
156157

157-
configureTypeContribution(type.toClass(), aotContext);
158-
aotContext.contributeTypeConfigurations(generationContext);
158+
configureTypeHints(type.toClass(), aotContext);
159159

160160
TypeUtils.resolveUsedAnnotations(type.toClass()).forEach(
161161
annotation -> TypeContributor.contribute(annotation.getType(), annotationNamespaces, generationContext));
@@ -168,7 +168,7 @@ protected void contributeType(ResolvableType type, GenerationContext generationC
168168
* @param aotContext AOT context for type configuration.
169169
* @since 4.0
170170
*/
171-
protected void configureTypeContribution(Class<?> type, AotContext aotContext) {
171+
protected void configureTypeHints(Class<?> type, AotContext aotContext) {
172172
aotContext.typeConfiguration(type, config -> config.forDataBinding().contributeAccessors().forQuerydsl());
173173
}
174174

src/main/java/org/springframework/data/aot/ManagedTypesRegistrationAotContribution.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ public void applyTo(GenerationContext generationContext, BeanRegistrationCode be
9898

9999
if (!types.isEmpty()) {
100100
TypeCollector.inspect(typeCollectorCustomizer, types)
101-
.forEach(type -> contributionAction.register(type, generationContext, aotContext));
101+
.forEach(type -> contributionAction.register(type, aotContext, generationContext));
102102
}
103+
104+
aotContext.contributeTypeConfigurations(generationContext);
103105
}
104106

105107
@Override
@@ -117,7 +119,7 @@ public RegisteredBean getSource() {
117119
}
118120

119121
interface TypeRegistration {
120-
void register(ResolvableType type, GenerationContext generationContext, AotContext aotContext);
122+
void register(ResolvableType type, AotContext aotContext, GenerationContext generationContext);
121123
}
122124

123125
/**

src/main/java/org/springframework/data/repository/config/RepositoryRegistrationAotProcessor.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
* not match due to customization of the factory bean by the user, at least the target repository type is provided via
6868
* the {@link FactoryBean#OBJECT_TYPE_ATTRIBUTE}.
6969
* <p>
70-
* With {@link RepositoryRegistrationAotProcessor#contributeRepositoryHints(AotRepositoryContext, GenerationContext)}
71-
* and {@link RepositoryRegistrationAotProcessor#contributeAotRepository(AotRepositoryContext)}, stores can provide
72-
* custom logic for contributing additional (e.g. reflection) configuration. By default, reflection configuration will
73-
* be added for types reachable from the repository declaration and query methods as well as all used {@link Annotation
74-
* annotations} from the {@literal org.springframework.data} namespace.
70+
* With {@link #registerRepositoryCompositionHints(AotRepositoryContext, GenerationContext)} (specifically
71+
* {@link #configureTypeContribution(Class, AotContext)} and {@link #contributeAotRepository(AotRepositoryContext)},
72+
* stores can provide custom logic for contributing additional (e.g. reflection) configuration. By default, reflection
73+
* configuration will be added for types reachable from the repository declaration and query methods as well as all used
74+
* {@link Annotation annotations} from the {@literal org.springframework.data} namespace.
7575
* <p>
7676
* The processor is typically configured via {@link RepositoryConfigurationExtension#getRepositoryAotProcessor()} and
7777
* gets added by the {@link org.springframework.data.repository.config.RepositoryConfigurationDelegate}.
@@ -163,8 +163,8 @@ protected ConfigurableListableBeanFactory getBeanFactory() {
163163

164164
BeanRegistrationAotContribution contribution = (generationContext, beanRegistrationCode) -> {
165165

166-
contributeRepositoryHints(repositoryContext, generationContext);
167-
contributeTypes(repositoryContext, generationContext);
166+
registerRepositoryCompositionHints(repositoryContext, generationContext);
167+
configureTypeContributions(repositoryContext, generationContext);
168168

169169
repositoryContext.contributeTypeConfigurations(generationContext);
170170
};
@@ -181,7 +181,7 @@ protected ConfigurableListableBeanFactory getBeanFactory() {
181181
* @param generationContext the generation context.
182182
* @since 4.0
183183
*/
184-
protected void contributeRepositoryHints(AotRepositoryContext repositoryContext,
184+
protected void registerRepositoryCompositionHints(AotRepositoryContext repositoryContext,
185185
GenerationContext generationContext) {
186186

187187
RepositoryInformation repositoryInformation = repositoryContext.getRepositoryInformation();
@@ -200,7 +200,7 @@ protected void contributeRepositoryHints(AotRepositoryContext repositoryContext,
200200
.forReflectiveAccess(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS));
201201

202202
// Repository Fragments
203-
contributeFragments(repositoryInformation.getFragments(), generationContext);
203+
registerFragmentsHints(repositoryInformation.getFragments(), generationContext);
204204

205205
// Kotlin
206206
if (isKotlinCoroutineRepository(repositoryInformation)) {
@@ -209,20 +209,19 @@ protected void contributeRepositoryHints(AotRepositoryContext repositoryContext,
209209
}
210210

211211
/**
212-
* Contribute types for reflection, proxies, etc. Customization hook for subclasses that wish to customize type
213-
* contribution hints.
212+
* Register type-specific hints and AOT artifacts for domain types, reachable types, projection interfaces derived
213+
* from query method return types, and annotations from {@literal org.springframework.data} packages.
214214
*
215215
* @param repositoryContext the repository context.
216216
* @param generationContext the generation context.
217217
* @since 4.0
218218
*/
219-
protected void contributeTypes(AotRepositoryContext repositoryContext, GenerationContext generationContext) {
220-
221-
contributeDomainTypes(repositoryContext, generationContext);
222-
contributeResolvedTypes(repositoryContext, generationContext);
219+
private void configureTypeContributions(AotRepositoryContext repositoryContext, GenerationContext generationContext) {
223220

224221
RepositoryInformation information = repositoryContext.getRepositoryInformation();
225222

223+
configureDomainTypeContributions(repositoryContext, generationContext);
224+
226225
// Repository query methods
227226
information.getQueryMethods().stream().map(information::getReturnedDomainClass).filter(Class::isInterface)
228227
.forEach(type -> {
@@ -238,44 +237,50 @@ protected void contributeTypes(AotRepositoryContext repositoryContext, Generatio
238237
}
239238

240239
/**
241-
* Customization hook for subclasses that wish to customize domain type contribution hints.
240+
* Customization hook for subclasses that wish to customize domain type hint contributions.
241+
* <p>
242+
* Type hints are registered for the domain, alternative domain types, and types reachable from there
243+
* ({@link AotRepositoryContext#getResolvedTypes()})
242244
*
243245
* @param repositoryContext the repository context.
244246
* @param generationContext the generation context.
245247
* @since 4.0
246248
*/
247-
protected void contributeDomainTypes(AotRepositoryContext repositoryContext, GenerationContext generationContext) {
249+
protected void configureDomainTypeContributions(AotRepositoryContext repositoryContext,
250+
GenerationContext generationContext) {
248251

249252
RepositoryInformation information = repositoryContext.getRepositoryInformation();
250-
251253
RuntimeHints hints = generationContext.getRuntimeHints();
252254

253255
// Domain types, related types, projections
254-
repositoryContext.typeConfiguration(information.getDomainType(), config -> config.forDataBinding().forQuerydsl());
255-
256256
ReflectiveRuntimeHintsRegistrar registrar = new ReflectiveRuntimeHintsRegistrar();
257257
Stream.concat(Stream.of(information.getDomainType()), information.getAlternativeDomainTypes().stream())
258258
.forEach(it -> {
259259

260-
// TODO cross check with #contributeResolvedTypes
261260
registrar.registerRuntimeHints(hints, it);
262-
repositoryContext.typeConfiguration(it, AotTypeConfiguration::contributeAccessors);
261+
configureTypeContribution(it, repositoryContext);
263262
});
264-
}
265263

266-
private void contributeResolvedTypes(AotRepositoryContext repositoryContext, GenerationContext generationContext) {
267-
268-
RepositoryInformation information = repositoryContext.getRepositoryInformation();
269-
270-
// TODO: These are twice.
264+
// TODO: Looks like a duplicate
271265
repositoryContext.getResolvedTypes().stream()
272266
.filter(it -> TypeContributor.isPartOf(it, Set.of(information.getDomainType().getPackageName())))
273-
.forEach(it -> repositoryContext.typeConfiguration(it, AotTypeConfiguration::contributeAccessors));
267+
.forEach(it -> configureTypeContribution(it, repositoryContext));
274268

275269
repositoryContext.getResolvedTypes().stream().filter(it -> !isJavaOrPrimitiveType(it))
276270
.forEach(it -> contributeType(it, generationContext));
277271
}
278272

273+
/**
274+
* Customization hook to configure the {@link TypeContributor} used to register the given {@literal type}.
275+
*
276+
* @param type the class to configure the contribution for.
277+
* @param aotContext AOT context for type configuration.
278+
* @since 4.0
279+
*/
280+
protected void configureTypeContribution(Class<?> type, AotContext aotContext) {
281+
aotContext.typeConfiguration(type, config -> config.forDataBinding().contributeAccessors().forQuerydsl());
282+
}
283+
279284
/**
280285
* This method allows for the creation to be overridden by subclasses.
281286
*
@@ -308,11 +313,11 @@ private void contributeType(Class<?> type, GenerationContext context) {
308313
TypeContributor.contribute(type, it -> true, context);
309314
}
310315

311-
private void contributeFragments(Iterable<RepositoryFragment<?>> fragments, GenerationContext contribution) {
312-
fragments.forEach(it -> contributeFragment(it, contribution));
316+
private void registerFragmentsHints(Iterable<RepositoryFragment<?>> fragments, GenerationContext contribution) {
317+
fragments.forEach(it -> registerFragmentHints(it, contribution));
313318
}
314319

315-
private static void contributeFragment(RepositoryFragment<?> fragment, GenerationContext context) {
320+
private static void registerFragmentHints(RepositoryFragment<?> fragment, GenerationContext context) {
316321

317322
Class<?> repositoryFragmentType = fragment.getSignatureContributor();
318323
Optional<Class<?>> implementation = fragment.getImplementationClass();

0 commit comments

Comments
 (0)