Search in sources :

Example 41 with MethodMetadata

use of org.springframework.core.type.MethodMetadata in project spring-boot by spring-projects.

the class NoSuchBeanDefinitionFailureAnalyzer method collectReportedConditionOutcomes.

private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, List<AutoConfigurationResult> results) {
    for (Map.Entry<String, ConditionAndOutcomes> entry : this.report.getConditionAndOutcomesBySource().entrySet()) {
        Source source = new Source(entry.getKey());
        ConditionAndOutcomes conditionAndOutcomes = entry.getValue();
        if (!conditionAndOutcomes.isFullMatch()) {
            BeanMethods methods = new BeanMethods(source, cause);
            for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
                if (!conditionAndOutcome.getOutcome().isMatch()) {
                    for (MethodMetadata method : methods) {
                        results.add(new AutoConfigurationResult(method, conditionAndOutcome.getOutcome(), source.isMethod()));
                    }
                }
            }
        }
    }
}
Also used : ConditionAndOutcomes(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes) ConditionAndOutcome(org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome) MethodMetadata(org.springframework.core.type.MethodMetadata) Map(java.util.Map)

Example 42 with MethodMetadata

use of org.springframework.core.type.MethodMetadata in project spring-boot by spring-projects.

the class BeanTypeRegistry method getFactoryMethod.

private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition) throws Exception {
    if (definition instanceof AnnotatedBeanDefinition) {
        MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata();
        if (factoryMethodMetadata instanceof StandardMethodMetadata) {
            return ((StandardMethodMetadata) factoryMethodMetadata).getIntrospectedMethod();
        }
    }
    BeanDefinition factoryDefinition = beanFactory.getBeanDefinition(definition.getFactoryBeanName());
    Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(), beanFactory.getBeanClassLoader());
    return getFactoryMethod(definition, factoryClass);
}
Also used : AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) MethodMetadata(org.springframework.core.type.MethodMetadata) StandardMethodMetadata(org.springframework.core.type.StandardMethodMetadata) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) StandardMethodMetadata(org.springframework.core.type.StandardMethodMetadata)

Example 43 with MethodMetadata

use of org.springframework.core.type.MethodMetadata in project spring-boot by spring-projects.

the class AbstractConfigurationClassTests method allBeanMethodsArePublic.

@Test
public void allBeanMethodsArePublic() throws IOException, ClassNotFoundException {
    Set<String> nonPublicBeanMethods = new HashSet<>();
    for (AnnotationMetadata configurationClass : findConfigurationClasses()) {
        Set<MethodMetadata> beanMethods = configurationClass.getAnnotatedMethods(Bean.class.getName());
        for (MethodMetadata methodMetadata : beanMethods) {
            if (!isPublic(methodMetadata)) {
                nonPublicBeanMethods.add(methodMetadata.getDeclaringClassName() + "." + methodMetadata.getMethodName());
            }
        }
    }
    assertThat(nonPublicBeanMethods).as("Found non-public @Bean methods").isEmpty();
}
Also used : MethodMetadata(org.springframework.core.type.MethodMetadata) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean) Test(org.junit.Test)

Example 44 with MethodMetadata

use of org.springframework.core.type.MethodMetadata in project spring-data-commons by spring-projects.

the class DefaultMethodsMetadataReaderUnitTests method shouldReadClassMethods.

// DATACMNS-1206
@Test
void shouldReadClassMethods() throws IOException {
    MethodsMetadata metadata = getMethodsMetadata(Foo.class);
    assertThat(metadata.getMethods()).hasSize(3);
    Iterator<MethodMetadata> iterator = metadata.getMethods().iterator();
    assertThat(iterator.next().getMethodName()).isEqualTo("one");
    assertThat(iterator.next().getMethodName()).isEqualTo("two");
    assertThat(iterator.next().getMethodName()).isEqualTo("three");
}
Also used : MethodsMetadata(org.springframework.data.type.MethodsMetadata) MethodMetadata(org.springframework.core.type.MethodMetadata) Test(org.junit.jupiter.api.Test)

Example 45 with MethodMetadata

use of org.springframework.core.type.MethodMetadata in project spring-data-commons by spring-projects.

the class DefaultMethodsMetadataReaderUnitTests method shouldReadInterfaceMethods.

// DATACMNS-1206
@Test
void shouldReadInterfaceMethods() throws IOException {
    MethodsMetadata metadata = getMethodsMetadata(Baz.class);
    assertThat(metadata.getMethods()).hasSize(3);
    Iterator<MethodMetadata> iterator = metadata.getMethods().iterator();
    assertThat(iterator.next().getMethodName()).isEqualTo("one");
    assertThat(iterator.next().getMethodName()).isEqualTo("two");
    assertThat(iterator.next().getMethodName()).isEqualTo("three");
}
Also used : MethodsMetadata(org.springframework.data.type.MethodsMetadata) MethodMetadata(org.springframework.core.type.MethodMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

MethodMetadata (org.springframework.core.type.MethodMetadata)73 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)33 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)32 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)20 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)15 StandardMethodMetadata (org.springframework.core.type.StandardMethodMetadata)14 ArrayList (java.util.ArrayList)12 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)12 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)12 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)11 Map (java.util.Map)10 StandardAnnotationMetadata (org.springframework.core.type.StandardAnnotationMetadata)10 Method (java.lang.reflect.Method)9 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)9 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)8 Bean (org.springframework.context.annotation.Bean)8 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)6 NestedIOException (org.springframework.core.NestedIOException)6