Skip to content

Commit 3e3f051

Browse files
committed
Polishing
1 parent 2d1d14b commit 3e3f051

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableL
344344
@Nullable
345345
private Resource resolvePropertySourceLocation(String location) {
346346
try {
347-
String resolvedLocation = (this.environment != null
348-
? this.environment.resolveRequiredPlaceholders(location) : location);
347+
String resolvedLocation = (this.environment != null ?
348+
this.environment.resolveRequiredPlaceholders(location) : location);
349349
return this.resourceLoader.getResource(resolvedLocation);
350350
}
351351
catch (Exception ex) {
@@ -598,15 +598,11 @@ public void applyTo(GenerationContext generationContext,
598598

599599
Map<String, String> mappings = buildImportAwareMappings();
600600
if (!mappings.isEmpty()) {
601-
GeneratedMethod generatedMethod = beanFactoryInitializationCode
602-
.getMethods()
603-
.add("addImportAwareBeanPostProcessors", method ->
604-
generateAddPostProcessorMethod(method, mappings));
605-
beanFactoryInitializationCode
606-
.addInitializer(generatedMethod.toMethodReference());
601+
GeneratedMethod generatedMethod = beanFactoryInitializationCode.getMethods().add(
602+
"addImportAwareBeanPostProcessors", method -> generateAddPostProcessorMethod(method, mappings));
603+
beanFactoryInitializationCode.addInitializer(generatedMethod.toMethodReference());
607604
ResourceHints hints = generationContext.getRuntimeHints().resources();
608-
mappings.forEach(
609-
(target, from) -> hints.registerType(TypeReference.of(from)));
605+
mappings.forEach((target, from) -> hints.registerType(TypeReference.of(from)));
610606
}
611607
}
612608

@@ -635,8 +631,7 @@ private CodeBlock generateAddPostProcessorCode(Map<String, String> mappings) {
635631
}
636632

637633
private Map<String, String> buildImportAwareMappings() {
638-
ImportRegistry importRegistry = this.beanFactory
639-
.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class);
634+
ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class);
640635
Map<String, String> mappings = new LinkedHashMap<>();
641636
for (String name : this.beanFactory.getBeanDefinitionNames()) {
642637
Class<?> beanType = this.beanFactory.getType(name);
@@ -671,11 +666,9 @@ private static class PropertySourcesAotContribution implements BeanFactoryInitia
671666
@Override
672667
public void applyTo(GenerationContext generationContext, BeanFactoryInitializationCode beanFactoryInitializationCode) {
673668
registerRuntimeHints(generationContext.getRuntimeHints());
674-
GeneratedMethod generatedMethod = beanFactoryInitializationCode
675-
.getMethods()
669+
GeneratedMethod generatedMethod = beanFactoryInitializationCode.getMethods()
676670
.add("processPropertySources", this::generateAddPropertySourceProcessorMethod);
677-
beanFactoryInitializationCode
678-
.addInitializer(generatedMethod.toMethodReference());
671+
beanFactoryInitializationCode.addInitializer(generatedMethod.toMethodReference());
679672
}
680673

681674
private void registerRuntimeHints(RuntimeHints hints) {
@@ -686,8 +679,8 @@ private void registerRuntimeHints(RuntimeHints hints) {
686679
}
687680
for (String location : descriptor.locations()) {
688681
Resource resource = this.resourceResolver.apply(location);
689-
if (resource != null && resource.exists() && resource instanceof ClassPathResource classpathResource) {
690-
hints.resources().registerPattern(classpathResource.getPath());
682+
if (resource instanceof ClassPathResource classPathResource && classPathResource.exists()) {
683+
hints.resources().registerPattern(classPathResource.getPath());
691684
}
692685
}
693686
}
@@ -723,8 +716,8 @@ private CodeBlock generatePropertySourceDescriptorCode(PropertySourceDescriptor
723716
code.add("new $T(", PropertySourceDescriptor.class);
724717
CodeBlock values = descriptor.locations().stream()
725718
.map(value -> CodeBlock.of("$S", value)).collect(CodeBlock.joining(", "));
726-
if (descriptor.name() == null && descriptor.propertySourceFactory() == null
727-
&& descriptor.encoding() == null && !descriptor.ignoreResourceNotFound()) {
719+
if (descriptor.name() == null && descriptor.propertySourceFactory() == null &&
720+
descriptor.encoding() == null && !descriptor.ignoreResourceNotFound()) {
728721
code.add("$L)", values);
729722
}
730723
else {

0 commit comments

Comments
 (0)