Skip to content

Commit

Permalink
Merge pull request #24000 from MattGill98/cdi-tck-fix-2
Browse files Browse the repository at this point in the history
Helidon Config - CDI TCK Fix 2
  • Loading branch information
arjantijms authored Jun 17, 2022
2 parents e9245dc + cb1d11b commit e9fe278
Showing 1 changed file with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -70,6 +71,8 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.config.spi.Converter;

import static java.util.Optional.ofNullable;

/**
* Extension to enable config injection in CDI container (all of {@link io.helidon.config.Config},
* {@link org.eclipse.microprofile.config.Config} and {@link ConfigProperty}).
Expand Down Expand Up @@ -140,24 +143,13 @@ private <X> void harvestConfigPropertyInjectionPointsFromEnabledObserverMethod(@
// Synthetic events won't have an annotated method
if (event instanceof ProcessSyntheticObserverMethod) return;

AnnotatedMethod<X> annotatedMethod = event.getAnnotatedMethod();
List<AnnotatedParameter<X>> annotatedParameters = annotatedMethod.getParameters();
if (annotatedParameters != null) {
for (AnnotatedParameter<?> annotatedParameter : annotatedParameters) {
if ((annotatedParameter != null)
&& !annotatedParameter.isAnnotationPresent(Observes.class)) {
InjectionPoint injectionPoint = beanManager.createInjectionPoint(annotatedParameter);
Set<Annotation> qualifiers = injectionPoint.getQualifiers();
assert qualifiers != null;
for (Annotation qualifier : qualifiers) {
if (qualifier instanceof ConfigProperty) {
ips.add(injectionPoint);
break;
}
}
}
}
}
ofNullable(event.getAnnotatedMethod())
.map(AnnotatedMethod::getParameters)
.stream().flatMap(Collection::stream)
.filter(parameter -> !parameter.isAnnotationPresent(Observes.class)
&& parameter.isAnnotationPresent(ConfigProperty.class))
.map(beanManager::createInjectionPoint)
.forEach(ips::add);
}

/**
Expand Down Expand Up @@ -382,10 +374,9 @@ private static Object parameterizedConfigValue(Config config,
Class<?> typeArg2) {
if (Optional.class.isAssignableFrom(rawType)) {
if (typeArg.equals(typeArg2)) {
return Optional.ofNullable(withDefault(config, configKey, typeArg, defaultValue, false));
return ofNullable(withDefault(config, configKey, typeArg, defaultValue, false));
} else {
return Optional
.ofNullable(parameterizedConfigValue(config,
return ofNullable(parameterizedConfigValue(config,
configKey,
defaultValue,
typeArg,
Expand Down

0 comments on commit e9fe278

Please sign in to comment.