|
4 | 4 | import io.avaje.inject.Primary;
|
5 | 5 | import io.avaje.inject.Secondary;
|
6 | 6 |
|
7 |
| -import javax.annotation.PostConstruct; |
8 |
| -import javax.annotation.PreDestroy; |
9 | 7 | import javax.inject.Inject;
|
10 | 8 | import javax.inject.Named;
|
11 | 9 | import javax.inject.Qualifier;
|
@@ -71,7 +69,7 @@ class BeanReader {
|
71 | 69 | BeanReader(TypeElement beanType, ProcessingContext context) {
|
72 | 70 | this.beanType = beanType;
|
73 | 71 | this.type = beanType.getQualifiedName().toString();
|
74 |
| - this.shortName = beanType.getSimpleName().toString(); |
| 72 | + this.shortName = shortName(beanType); |
75 | 73 | this.context = context;
|
76 | 74 | this.requestParams = new BeanRequestParams(type);
|
77 | 75 | init();
|
@@ -267,18 +265,35 @@ private void readMethod(Element element, boolean factory) {
|
267 | 265 | }
|
268 | 266 |
|
269 | 267 | if (context.isPostConstructAvailable()) {
|
270 |
| - PostConstruct pcMarker = element.getAnnotation(PostConstruct.class); |
271 |
| - if (pcMarker != null) { |
| 268 | + if (hasAnnotationWithName(element, "PostConstruct")) { |
272 | 269 | postConstructMethod = element;
|
273 | 270 | }
|
274 | 271 |
|
275 |
| - PreDestroy pdMarker = element.getAnnotation(PreDestroy.class); |
276 |
| - if (pdMarker != null) { |
| 272 | + if (hasAnnotationWithName(element, "PreDestroy")) { |
277 | 273 | preDestroyMethod = element;
|
278 | 274 | }
|
279 | 275 | }
|
280 | 276 | }
|
281 | 277 |
|
| 278 | + /** |
| 279 | + * Return true if the element has an annotation with the matching short name. |
| 280 | + */ |
| 281 | + private boolean hasAnnotationWithName(Element element, String matchShortName) { |
| 282 | + for (AnnotationMirror mirror : element.getAnnotationMirrors()) { |
| 283 | + if (matchShortName.equals(shortName(mirror.getAnnotationType().asElement()))) { |
| 284 | + return true; |
| 285 | + } |
| 286 | + } |
| 287 | + return false; |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * Return the short name of the element. |
| 292 | + */ |
| 293 | + private String shortName(Element element) { |
| 294 | + return element.getSimpleName().toString(); |
| 295 | + } |
| 296 | + |
282 | 297 | private void addFactoryMethod(ExecutableElement methodElement, Bean bean) {
|
283 | 298 | // Not yet reading Qualifier annotations, Named only at this stage
|
284 | 299 | Named named = methodElement.getAnnotation(Named.class);
|
|
0 commit comments