diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java b/implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java index 89074e12e..cb5582254 100644 --- a/implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java +++ b/implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.smallrye.config.inject; import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; @@ -34,7 +33,6 @@ import javax.enterprise.inject.Instance; import javax.enterprise.inject.spi.AfterBeanDiscovery; import javax.enterprise.inject.spi.AfterDeploymentValidation; -import javax.enterprise.inject.spi.AnnotatedMember; import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.BeforeBeanDiscovery; @@ -120,7 +118,7 @@ void validate(@Observes AfterDeploymentValidation adv) { } ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class); - String name = getConfigKey(injectionPoint, configProperty); + String name = ConfigProducerUtil.getConfigKey(injectionPoint, configProperty); // Check if the name is part of the properties first. Since properties can be a subset, then search for the actual property for a value. if (!configNames.contains(name) && ConfigProducerUtil.getRawValue(name, (SmallRyeConfig) config) == null) { @@ -142,27 +140,6 @@ void validate(@Observes AfterDeploymentValidation adv) { } } - static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) { - String key = configProperty.name(); - if (!key.trim().isEmpty()) { - return key; - } - if (ip.getAnnotated() instanceof AnnotatedMember) { - AnnotatedMember member = (AnnotatedMember) ip.getAnnotated(); - AnnotatedType declaringType = member.getDeclaringType(); - if (declaringType != null) { - String[] parts = declaringType.getJavaClass().getCanonicalName().split("\\."); - StringBuilder sb = new StringBuilder(parts[0]); - for (int i = 1; i < parts.length; i++) { - sb.append(".").append(parts[i]); - } - sb.append(".").append(member.getJavaMember().getName()); - return sb.toString(); - } - } - throw InjectionMessages.msg.noConfigPropertyDefaultName(ip); - } - private static boolean isClassHandledByConfigProducer(Type requiredType) { return requiredType == String.class || requiredType == Boolean.class diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java b/implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java index c7f80ddaa..b66907ee4 100644 --- a/implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java +++ b/implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.smallrye.config.inject; import java.lang.annotation.Annotation; @@ -86,7 +85,7 @@ public T create(CreationalContext context) { InjectionPoint ip = (InjectionPoint) bm.getInjectableReference(new InjectionPointMetadataInjectionPoint(), context); Annotated annotated = ip.getAnnotated(); ConfigProperty configProperty = annotated.getAnnotation(ConfigProperty.class); - String key = ConfigExtension.getConfigKey(ip, configProperty); + String key = ConfigProducerUtil.getConfigKey(ip, configProperty); String defaultValue = configProperty.defaultValue(); if (annotated.getBaseType() instanceof ParameterizedType) { diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java b/implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java index d7f328564..c22c49bd4 100644 --- a/implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java +++ b/implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java @@ -12,6 +12,8 @@ import java.util.Set; import java.util.function.Supplier; +import javax.enterprise.inject.spi.AnnotatedMember; +import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.InjectionPoint; import org.eclipse.microprofile.config.Config; @@ -120,13 +122,13 @@ public static String getName(InjectionPoint injectionPoint) { for (Annotation qualifier : injectionPoint.getQualifiers()) { if (qualifier.annotationType().equals(ConfigProperty.class)) { ConfigProperty configProperty = ((ConfigProperty) qualifier); - return ConfigExtension.getConfigKey(injectionPoint, configProperty); + return getConfigKey(injectionPoint, configProperty); } } return null; } - private static String getDefaultValue(InjectionPoint injectionPoint) { + public static String getDefaultValue(InjectionPoint injectionPoint) { for (Annotation qualifier : injectionPoint.getQualifiers()) { if (qualifier.annotationType().equals(ConfigProperty.class)) { String str = ((ConfigProperty) qualifier).defaultValue(); @@ -148,4 +150,25 @@ private static String getDefaultValue(InjectionPoint injectionPoint) { } return null; } + + static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) { + String key = configProperty.name(); + if (!key.trim().isEmpty()) { + return key; + } + if (ip.getAnnotated() instanceof AnnotatedMember) { + AnnotatedMember member = (AnnotatedMember) ip.getAnnotated(); + AnnotatedType declaringType = member.getDeclaringType(); + if (declaringType != null) { + String[] parts = declaringType.getJavaClass().getCanonicalName().split("\\."); + StringBuilder sb = new StringBuilder(parts[0]); + for (int i = 1; i < parts.length; i++) { + sb.append(".").append(parts[i]); + } + sb.append(".").append(member.getJavaMember().getName()); + return sb.toString(); + } + } + throw InjectionMessages.msg.noConfigPropertyDefaultName(ip); + } }