TAMAYA-260 - Improve how parameterized types are handled.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/794def9c Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/794def9c Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/794def9c Branch: refs/heads/TAMAYA-260-mp-11 Commit: 794def9cf62f03b569820d92676202bd11167e08 Parents: acf2b6f Author: John D. Ament <[email protected]> Authored: Wed Sep 20 23:35:59 2017 -0400 Committer: John D. Ament <[email protected]> Committed: Wed Sep 20 23:35:59 2017 -0400 ---------------------------------------------------------------------- .../cdi/MicroprofileCDIExtension.java | 39 +++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/794def9c/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java ---------------------------------------------------------------------- diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java index 7a819fc..0e30b78 100644 --- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java +++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java @@ -19,12 +19,19 @@ package org.apache.tamaya.microprofile.cdi; import org.eclipse.microprofile.config.inject.ConfigProperty; import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.*; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; +import javax.enterprise.inject.Instance; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.ProcessBean; +import javax.enterprise.inject.spi.ProcessProducerMethod; +import javax.inject.Provider; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Logger; @@ -61,17 +68,12 @@ public class MicroprofileCDIExtension implements Extension { boolean configured = false; for (InjectionPoint injectionPoint : ips) { if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - System.err.println("Configured: " + injectionPoint); + LOG.fine("Configuring: " + injectionPoint); final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class); String key = !annotation.name().isEmpty()?annotation.name():MicroprofileConfigurationProducer.getDefaultKey(injectionPoint); - Member member = injectionPoint.getMember(); - if(member instanceof Field) { - types.add(((Field) member).getType()); - }else if(member instanceof Method){ - types.add(((Method) member).getParameterTypes()[0]); - }else{ - continue; - } + Type originalType = injectionPoint.getType(); + Type convertedType = unwrapType(originalType); + types.add(convertedType); configured = true; LOG.finest(() -> "Enabling Tamaya Microprofile Configuration on bean: " + configuredType.getName()); configuredType.addConfiguredMember(injectionPoint, key); @@ -95,5 +97,14 @@ public class MicroprofileCDIExtension implements Extension { } } + private Type unwrapType(Type type) { + if(type instanceof ParameterizedType) { + Type rawType = ((ParameterizedType) type).getRawType(); + if(rawType == Provider.class || rawType == Instance.class) { + return ((ParameterizedType) type).getActualTypeArguments()[0]; + } + } + return type; + } }
