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

TAKETODAY / today-infrastructure / 16489896461

24 Jul 2025 06:51AM UTC coverage: 81.782%. Remained the same
16489896461

push

github

TAKETODAY
:sparkles: LogMessage API

59446 of 77637 branches covered (76.57%)

Branch coverage included in aggregate %.

140767 of 167176 relevant lines covered (84.2%)

3.6 hits per line

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

93.33
today-context/src/main/java/infra/context/annotation/BeanAnnotationHelper.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.annotation;
19

20
import java.lang.reflect.Method;
21

22
import infra.beans.factory.config.ConfigurableBeanFactory;
23
import infra.core.annotation.AnnotatedElementUtils;
24
import infra.core.annotation.AnnotationAttributes;
25
import infra.core.type.MethodMetadata;
26
import infra.stereotype.Component;
27
import infra.util.ConcurrentReferenceHashMap;
28

29
/**
30
 * Utilities for processing {@link Component}-annotated methods.
31
 *
32
 * @author Chris Beams
33
 * @author Juergen Hoeller
34
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
35
 * @since 4.0
36
 */
37
abstract class BeanAnnotationHelper {
×
38

39
  private static final ConcurrentReferenceHashMap<Method, String> beanNameCache
4✔
40
          = new ConcurrentReferenceHashMap<>();
41

42
  private static final ConcurrentReferenceHashMap<Method, Boolean> scopedProxyCache
5✔
43
          = new ConcurrentReferenceHashMap<>();
44

45
  public static boolean isBeanAnnotated(Method method) {
46
    return AnnotatedElementUtils.hasAnnotation(method, Component.class);
4✔
47
  }
48

49
  public static String determineBeanNameFor(Method beanMethod, ConfigurableBeanFactory beanFactory) {
50
    String beanName = retrieveBeanNameFor(beanMethod);
3✔
51
    if (!beanName.isEmpty()) {
3✔
52
      return beanName;
2✔
53
    }
54
    return beanFactory.getSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR) instanceof ConfigurationBeanNameGenerator cbng
11✔
55
            ? cbng.deriveBeanName(MethodMetadata.introspect(beanMethod)) : beanMethod.getName();
7✔
56
  }
57

58
  public static String determineBeanNameFor(Method beanMethod) {
59
    String beanName = retrieveBeanNameFor(beanMethod);
3✔
60
    return !beanName.isEmpty() ? beanName : beanMethod.getName();
8✔
61
  }
62

63
  private static String retrieveBeanNameFor(Method beanMethod) {
64
    String beanName = beanNameCache.get(beanMethod);
5✔
65
    if (beanName == null) {
2✔
66
      // By default, the bean name is empty (indicating a name to be derived from the method name)
67
      beanName = "";
2✔
68
      // Check to see if the user has explicitly set a custom bean name...
69
      AnnotationAttributes bean = AnnotatedElementUtils.findMergedAnnotationAttributes(
6✔
70
              beanMethod, Component.class, false, false);
71
      if (bean != null) {
2!
72
        String[] names = bean.getStringArray("name");
4✔
73
        if (names.length > 0) {
3✔
74
          beanName = names[0];
4✔
75
        }
76
      }
77
      beanNameCache.put(beanMethod, beanName);
5✔
78
    }
79
    return beanName;
2✔
80
  }
81

82
  public static boolean isScopedProxy(Method beanMethod) {
83
    Boolean scopedProxy = scopedProxyCache.get(beanMethod);
5✔
84
    if (scopedProxy == null) {
2✔
85
      AnnotationAttributes scope = AnnotatedElementUtils.findMergedAnnotationAttributes(
6✔
86
              beanMethod, Scope.class, false, false);
87
      scopedProxy = scope != null && scope.getEnum("proxyMode") != ScopedProxyMode.NO;
12!
88
      scopedProxyCache.put(beanMethod, scopedProxy);
5✔
89
    }
90
    return scopedProxy;
3✔
91
  }
92

93
}
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