use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.
the class OnAvailableEndpointCondition method getEndpointAnnotation.
protected MergedAnnotation<Endpoint> getEndpointAnnotation(Class<?> target) {
MergedAnnotations annotations = MergedAnnotations.from(target, SearchStrategy.TYPE_HIERARCHY);
MergedAnnotation<Endpoint> endpoint = annotations.get(Endpoint.class);
if (endpoint.isPresent()) {
return endpoint;
}
MergedAnnotation<EndpointExtension> extension = annotations.get(EndpointExtension.class);
Assert.state(extension.isPresent(), "No endpoint is specified and the return type of the @Bean method is " + "neither an @Endpoint, nor an @EndpointExtension");
return getEndpointAnnotation(extension.getClass("endpoint"));
}
use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.
the class OnBeanCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage matchMessage = ConditionMessage.empty();
MergedAnnotations annotations = metadata.getAnnotations();
if (annotations.isPresent(ConditionalOnBean.class)) {
Spec<ConditionalOnBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnBean.class);
MatchResult matchResult = getMatchingBeans(context, spec);
if (!matchResult.isAllMatched()) {
String reason = createOnBeanNoMatchReason(matchResult);
return ConditionOutcome.noMatch(spec.message().because(reason));
}
matchMessage = spec.message(matchMessage).found("bean", "beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches());
}
if (metadata.isAnnotated(ConditionalOnSingleCandidate.class.getName())) {
Spec<ConditionalOnSingleCandidate> spec = new SingleCandidateSpec(context, metadata, annotations);
MatchResult matchResult = getMatchingBeans(context, spec);
if (!matchResult.isAllMatched()) {
return ConditionOutcome.noMatch(spec.message().didNotFind("any beans").atAll());
} else if (!hasSingleAutowireCandidate(context.getBeanFactory(), matchResult.getNamesOfAllMatches(), spec.getStrategy() == SearchStrategy.ALL)) {
return ConditionOutcome.noMatch(spec.message().didNotFind("a primary bean from beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches()));
}
matchMessage = spec.message(matchMessage).found("a primary bean from beans").items(Style.QUOTE, matchResult.getNamesOfAllMatches());
}
if (metadata.isAnnotated(ConditionalOnMissingBean.class.getName())) {
Spec<ConditionalOnMissingBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnMissingBean.class);
MatchResult matchResult = getMatchingBeans(context, spec);
if (matchResult.isAnyMatched()) {
String reason = createOnMissingBeanNoMatchReason(matchResult);
return ConditionOutcome.noMatch(spec.message().because(reason));
}
matchMessage = spec.message(matchMessage).didNotFind("any beans").atAll();
}
return ConditionOutcome.match(matchMessage);
}
use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.
the class DefinitionsParser method parseElement.
private void parseElement(AnnotatedElement element, Class<?> source) {
MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.SUPERCLASS);
annotations.stream(MockBean.class).map(MergedAnnotation::synthesize).forEach((annotation) -> parseMockBeanAnnotation(annotation, element, source));
annotations.stream(SpyBean.class).map(MergedAnnotation::synthesize).forEach((annotation) -> parseSpyBeanAnnotation(annotation, element, source));
}
use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.
the class ModifiedClassPathClassLoader method compute.
private static ModifiedClassPathClassLoader compute(Class<?> testClass) {
ClassLoader classLoader = testClass.getClassLoader();
MergedAnnotations annotations = MergedAnnotations.from(testClass, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);
if (annotations.isPresent(ForkedClassPath.class) && (annotations.isPresent(ClassPathOverrides.class) || annotations.isPresent(ClassPathExclusions.class))) {
throw new IllegalStateException("@ForkedClassPath is redundant in combination with either " + "@ClassPathOverrides or @ClassPathExclusions");
}
return new ModifiedClassPathClassLoader(processUrls(extractUrls(classLoader), annotations), classLoader.getParent(), classLoader);
}
use of org.springframework.core.annotation.MergedAnnotations in project spring-boot by spring-projects.
the class TimedAnnotations method findTimedAnnotations.
private static Set<Timed> findTimedAnnotations(AnnotatedElement element) {
if (element == null) {
return Collections.emptySet();
}
Set<Timed> result = cache.get(element);
if (result != null) {
return result;
}
MergedAnnotations annotations = MergedAnnotations.from(element);
result = (!annotations.isPresent(Timed.class)) ? Collections.emptySet() : annotations.stream(Timed.class).collect(MergedAnnotationCollectors.toAnnotationSet());
cache.put(element, result);
return result;
}
Aggregations