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/3aad3568 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/3aad3568 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/3aad3568 Branch: refs/heads/master Commit: 3aad3568d532798a60a1636a5d54bcb264cdf309 Parents: 4200f87 Author: John D. Ament <[email protected]> Authored: Wed Sep 20 23:35:59 2017 -0400 Committer: John Ament <[email protected]> Committed: Tue Oct 3 13:49:30 2017 -0400 ---------------------------------------------------------------------- .../cdi/MicroprofileCDIExtension.java | 45 ++++++++++---------- tamaya-sandbox.iml | 12 ------ 2 files changed, 23 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/3aad3568/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 550b9e0..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 @@ -20,13 +20,18 @@ import org.eclipse.microprofile.config.inject.ConfigProperty; import javax.enterprise.event.Observes; import javax.enterprise.inject.Instance; -import javax.enterprise.inject.spi.*; +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.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; +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; @@ -63,25 +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) { - Field f = (Field)member; - if(!Instance.class.equals(f.getType()) && - !Provider.class.equals(f.getType())){ - types.add(f.getType()); - } - }else if(member instanceof Method){ - Method m = (Method)member; - if(!Instance.class.equals(m.getParameterTypes()[0]) && - !Provider.class.equals(m.getParameterTypes()[0])){ - types.add(m.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); @@ -105,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; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/3aad3568/tamaya-sandbox.iml ---------------------------------------------------------------------- diff --git a/tamaya-sandbox.iml b/tamaya-sandbox.iml deleted file mode 100644 index a0d4a1e..0000000 --- a/tamaya-sandbox.iml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4"> - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> - <output url="file://$MODULE_DIR$/target/classes" /> - <output-test url="file://$MODULE_DIR$/target/test-classes" /> - <content url="file://$MODULE_DIR$"> - <excludeFolder url="file://$MODULE_DIR$/target" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file
