Debian Codegraph @

api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BeanInfo.java

raw
1 /*
2 * Copyright (c) 2021 Red Hat and others
3 *
4 * This program and the accompanying materials are made available under the
5 * Apache Software License 2.0 which is available at:
6 * https://www.apache.org/licenses/LICENSE-2.0.
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11 package jakarta.enterprise.inject.build.compatible.spi;
12
13 import jakarta.enterprise.lang.model.AnnotationInfo;
14 import jakarta.enterprise.lang.model.declarations.ClassInfo;
15 import jakarta.enterprise.lang.model.declarations.FieldInfo;
16 import jakarta.enterprise.lang.model.declarations.MethodInfo;
17 import jakarta.enterprise.lang.model.types.Type;
18 import java.util.Collection;
19
20 /**
21 * Beans are:
22 *
23 * <ul>
24 * <li>managed beans</li>
25 * <li>beans defined by producer methods</li>
26 * <li>beans defined by producer fields</li>
27 * <li>synthetic beans</li>
28 * </ul>
29 *
30 * Managed beans are also known as class-based beans, while beans defined by producer methods
31 * and producer fields are together also known as producer-based beans.
32 * <p>
33 * Class-based and producer-based beans directly correspond to a declaration in program source code.
34 * Synthetic beans don't and are instead defined through other mechanisms, such as
35 * {@linkplain BuildCompatibleExtension extensions}.
36 *
37 * @since 4.0
38 */
39 public interface BeanInfo {
40 /**
41 * Returns the {@linkplain ScopeInfo scope} of this bean.
42 *
43 * @return the {@linkplain ScopeInfo scope} of this bean, never {@code null}
44 */
45 ScopeInfo scope();
46
47 /**
48 * Returns a collection of all {@linkplain Type types} of this bean.
49 *
50 * @return immutable collection of bean types, never {@code null}
51 */
52 Collection<Type> types();
53
54 /**
55 * Returns a collection of this bean's qualifiers, represented as {@link AnnotationInfo}.
56 *
57 * @return immutable collection of qualifiers, never {@code null}
58 */
59 Collection<AnnotationInfo> qualifiers();
60
61 /**
62 * Returns the class that declares this bean.
63 * In case of a managed bean, also known as class-based bean, that is the bean class directly.
64 * In case of a producer method or field, that is the class that declares the producer method or field.
65 * Returns {@code null} if this bean is synthetic.
66 *
67 * @return {@link ClassInfo} for the class that declares this bean, or {@code null} if this bean is synthetic
68 */
69 ClassInfo declaringClass();
70
71 /**
72 * Returns whether this bean is a managed bean, also known as class-based bean.
73 *
74 * @return whether this bean is a managed bean
75 */
76 boolean isClassBean();
77
78 /**
79 * Returns whether this bean is defined by a producer method.
80 *
81 * @return whether this bean is defined by a producer method
82 */
83 boolean isProducerMethod();
84
85 /**
86 * Returns whether this bean is defined by a producer field.
87 *
88 * @return whether this bean is defined by a producer field
89 */
90 boolean isProducerField();
91
92 /**
93 * Returns whether this bean is synthetic. In other words, whether this bean
94 * does not correspond to a declaration in program source code and was created
95 * through other means (e.g. using an extension).
96 *
97 * @return whether this bean is synthetic
98 */
99 boolean isSynthetic();
100
101 /**
102 * Returns the producer {@linkplain MethodInfo method} that defines this bean.
103 * Returns {@code null} if this bean is not defined by a producer method.
104 *
105 * @return producer method that defines this bean, or {@code null} if this bean is not defined by a producer method
106 */
107 MethodInfo producerMethod();
108
109 /**
110 * Returns the producer {@linkplain FieldInfo field} that defines this bean.
111 * Returns {@code null} if this bean is not defined by a producer field.
112 *
113 * @return producer field that defines this bean, or {@code null} if this bean is not defined by a producer field
114 */
115 FieldInfo producerField();
116
117 /**
118 * Returns whether this bean is an {@linkplain jakarta.enterprise.inject.Alternative alternative}.
119 *
120 * @return whether this bean is an {@linkplain jakarta.enterprise.inject.Alternative alternative}
121 */
122 boolean isAlternative();
123
124 /**
125 * Returns the {@linkplain jakarta.annotation.Priority priority} declared on this bean, or {@code null}
126 * if this bean does not declare a priority. Declaring a priority on an alternative bean makes it an enabled
127 * alternative. Similarly, declaring a priority on an interceptor makes it an enabled interceptor.
128 *
129 * @return the priority of this bean, or {@code null} if this bean does not declare a priority
130 */
131 Integer priority();
132
133 /**
134 * Returns the bean name of this bean. A bean name is usually defined
135 * using the {@link jakarta.inject.Named @Named} annotation.
136 * Returns {@code null} if the bean does not have a name.
137 *
138 * @return the bean name, or {@code null} if the bean does not have a name
139 */
140 String name();
141
142 /**
143 * Returns the {@linkplain DisposerInfo disposer} method of this producer-based bean.
144 * Returns {@code null} if this bean is not a defined by a producer method or a producer field,
145 * or if this producer-based bean does not have a corresponding disposer method.
146 *
147 * @return the {@linkplain DisposerInfo disposer}, or {@code null} if this bean does not have a disposer
148 */
149 DisposerInfo disposer();
150
151 /**
152 * Returns a collection of this bean's {@linkplain StereotypeInfo stereotypes}.
153 *
154 * @return immutable collection of stereotypes, never {@code null}
155 */
156 Collection<StereotypeInfo> stereotypes();
157
158 /**
159 * Returns a collection of this bean's {@linkplain InjectionPointInfo injection points}.
160 *
161 * @return immutable collection of injection points, never {@code null}
162 */
163 Collection<InjectionPointInfo> injectionPoints();
164
165 // ---
166
167 /**
168 * Returns whether this bean is an interceptor.
169 *
170 * @return whether this bean is an interceptor
171 */
172 default boolean isInterceptor() {
173 return false;
174 }
175
176 /**
177 * Returns this bean as an {@linkplain InterceptorInfo interceptor}.
178 *
179 * @return this interceptor, never {@code null}
180 * @throws IllegalStateException if {@link #isInterceptor()} returns {@code false}
181 */
182 default InterceptorInfo asInterceptor() {
183 throw new IllegalStateException("Not an interceptor");
184 }
185 }