• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
today-context/src/main/java/infra/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessor.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.context.aot;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.Arrays;
23
import java.util.Collections;
24
import java.util.LinkedHashSet;
25
import java.util.Set;
26

27
import infra.aot.hint.annotation.Reflective;
28
import infra.aot.hint.annotation.ReflectiveProcessor;
29
import infra.beans.factory.aot.BeanFactoryInitializationAotContribution;
30
import infra.beans.factory.aot.BeanFactoryInitializationAotProcessor;
31
import infra.beans.factory.config.ConfigurableBeanFactory;
32
import infra.beans.factory.support.RegisteredBean;
33
import infra.context.annotation.ReflectiveScan;
34
import infra.core.annotation.AnnotatedElementUtils;
35
import infra.util.ClassUtils;
36

37
/**
38
 * AOT {@code BeanFactoryInitializationAotProcessor} that detects the presence
39
 * of {@link Reflective @Reflective} on annotated elements of all registered
40
 * beans and invokes the underlying {@link ReflectiveProcessor} implementations.
41
 *
42
 * @author Stephane Nicoll
43
 * @author Sebastien Deleuze
44
 * @author <a href="https://github.com/TAKETODAY">海子 Yang</a>
45
 */
46
class ReflectiveProcessorBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
3✔
47

48
  @Override
49
  @Nullable
50
  public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableBeanFactory beanFactory) {
51
    Class<?>[] beanClasses = Arrays.stream(beanFactory.getBeanDefinitionNames())
5✔
52
            .map(beanName -> RegisteredBean.of(beanFactory, beanName).getBeanClass())
7✔
53
            .toArray(Class<?>[]::new);
6✔
54
    String[] packagesToScan = findBasePackagesToScan(beanClasses);
4✔
55
    return new ReflectiveProcessorAotContributionBuilder().withClasses(beanClasses)
7✔
56
            .scan(beanFactory.getBeanClassLoader(), packagesToScan).build();
4✔
57
  }
58

59
  protected String[] findBasePackagesToScan(Class<?>[] beanClasses) {
60
    Set<String> basePackages = new LinkedHashSet<>();
4✔
61
    for (Class<?> beanClass : beanClasses) {
16✔
62
      ReflectiveScan reflectiveScan = AnnotatedElementUtils.getMergedAnnotation(beanClass, ReflectiveScan.class);
5✔
63
      if (reflectiveScan != null) {
2✔
64
        basePackages.addAll(extractBasePackages(reflectiveScan, beanClass));
7✔
65
      }
66
    }
67
    return basePackages.toArray(new String[0]);
6✔
68
  }
69

70
  private Set<String> extractBasePackages(ReflectiveScan annotation, Class<?> declaringClass) {
71
    Set<String> basePackages = new LinkedHashSet<>();
4✔
72
    Collections.addAll(basePackages, annotation.basePackages());
5✔
73
    for (Class<?> clazz : annotation.basePackageClasses()) {
17✔
74
      basePackages.add(ClassUtils.getPackageName(clazz));
5✔
75
    }
76
    if (basePackages.isEmpty()) {
3!
77
      basePackages.add(ClassUtils.getPackageName(declaringClass));
×
78
    }
79
    return basePackages;
2✔
80
  }
81

82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc